Fix bug on select2 in modal filters, add filters by tags and shelves on articles

This commit is contained in:
Ludovic CANDELLIER
2022-01-30 15:04:08 +01:00
parent 5799eb36fc
commit 5e5f12ddb2
6 changed files with 64 additions and 15 deletions

View File

@@ -1,8 +1,20 @@
<form id="{{ $model }}-filters">
<div class="row">
<div class="row mb-3">
<label class="col-4">{{ __('shop.article_natures.title') }}</label>
<div class="col-8">
@include('components.form.select', ['name' => 'article_nature_id', 'list' => $article_natures ?? [], 'value' => $filters['article_nature_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' '])
</div>
</div>
<div class="row mb-3">
<label class="col-4">{{ __('shop.shelves.title') }}</label>
<div class="col-8">
@include('components.form.select', ['name' => 'category_id', 'list' => $categories ?? [], 'value' => $filters['category_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' '])
</div>
</div>
<div class="row mb-3">
<label class="col-4">{{ __('shop.tags.title') }}</label>
<div class="col-8">
@include('components.form.select', ['name' => 'tag_id', 'list' => $tags ?? [], 'value' => $filters['tag_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ' '])
</div>
</div>
</form>

View File

@@ -9,7 +9,7 @@
var $filter = $('#{{ $model ?? null }}-table-header .btn-filter');
$('#modal-{{ $model ?? null }}-filters').on('shown.bs.modal', function () {
initSelect2();
initSelect2('.select2', '#modal-{{ $model ?? null }}-filters');
});
$('#modal-{{ $model ?? null }}-filters .apply').click(function() {

View File

@@ -4,25 +4,43 @@
<script src="/assets/plugins/select2/js/i18n/{{ App::getLocale() }}.js"></script>
<script>
function initSelect2(sel) {
var selector = (typeof(sel) == 'undefined') ? '.select2' : sel;
$(selector).select2({
placeholder: "{{ __('select_a_value') }}",
allowClear: false,
width: {
value: '100%'
}
});
function initSelect2(sel, parent) {
console.log('initSelect2');
// $.fn.modal.Constructor.prototype.enforceFocus = function() {};
$(document).on('select2:open',(e) => {
var selector = (typeof(sel) == 'undefined') ? '.select2' : sel;
if (typeof(parent) == 'undefined') {
$(selector).select2({
placeholder: "{{ __('select_a_value') }}",
allowClear: false,
width: {
value: '100%'
}
});
} else {
$(selector).select2({
placeholder: "{{ __('select_a_value') }}",
allowClear: true,
dropdownParent: $(parent),
width: {
value: '100%'
}
});
}
/*
$(selector).on('select2:open',(e) => {
let t = $(e.target);
console.log(t);
if (t && t.length) {
let id = t[0].id || t[0].name;
let item = document.querySelector(`input[aria-controls*='${id}']`);
console.log(id);
let item = $(`input[aria-controls*='${id}']`);
console.log(item);
return item ? item.focus() : false;
}
});
*/
}
</script>
@endpush