Skip to content

Commit

Permalink
minimumResultsForSearch and maximumSelectionSize select2 options are …
Browse files Browse the repository at this point in the history
…configurable
  • Loading branch information
vincentlaurier authored and core23 committed Jan 8, 2020
1 parent cd69d7c commit 44b8206
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Resources/public/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ var Admin = {
Admin.log('[core|setup_select2] configure Select2 on', subject);

jQuery('select:not([data-sonata-select2="false"])', subject).each(function() {
var select = jQuery(this);
var allowClearEnabled = false;
var popover = select.data('popover');
var select = jQuery(this);
var allowClearEnabled = false;
var popover = select.data('popover');
var maximumSelectionSize = null;
var minimumResultsForSearch = 10;

select.removeClass('form-control');

Expand All @@ -109,15 +111,24 @@ var Admin = {
allowClearEnabled = false;
}

if (select.attr('data-sonata-select2-maximumSelectionSize')) {
maximumSelectionSize = select.attr('data-sonata-select2-maximumSelectionSize');
}

if (select.attr('data-sonata-select2-minimumResultsForSearch')) {
minimumResultsForSearch = select.attr('data-sonata-select2-minimumResultsForSearch');
}

select.select2({
width: function(){
// Select2 v3 and v4 BC. If window.Select2 is defined, then the v3 is installed.
// NEXT_MAJOR: Remove Select2 v3 support.
return Admin.get_select2_width(window.Select2 ? this.element : select);
},
dropdownAutoWidth: true,
minimumResultsForSearch: 10,
allowClear: allowClearEnabled
minimumResultsForSearch: minimumResultsForSearch,
allowClear: allowClearEnabled,
maximumSelectionSize: maximumSelectionSize
});

if (undefined !== popover) {
Expand Down

0 comments on commit 44b8206

Please sign in to comment.