Enable select2 multi-select selection window

I need to be able to add a search box to my multiple select fields using select2.

For any reason, while search fields appear as expected in fields with one choice, the same call to select2 () in a field with multiple choices does not add a search box.

var data = []; // Programatically-generated options array with > 5 options var placeholder = "select"; $(".mySelect").select2({ data: data, placeholder: placeholder, allowClear: false, minimumResultsForSearch: 5}); 

Does select2 not support multiple select search fields? Does anyone have a good similarly functioning alternative?

+10
source share
3 answers

The answer is that the select2 input element becomes a search field for multiple samples without back end data

if you start typing, your results will begin to filter options

if you have ajax installed to load remote data, it actually saves the search field, but for several samples without a data source, the input is a search panel that is pretty intuitive.

https://select2.imtqy.com/examples.html

+11
source

select2 v4.0.3

 <select class="smartsearch_keyword" name="keyword[]" id="keyword" style="width:100%;"></select> $(".smartsearch_keyword").select2({ multiple: true, ... }); 

Additionally: set multiple default options

+6
source

If none of the above answers work for you ( $(document).ready(function() {//your select2 declaration here... }); everything in $(document).ready(function() {//your select2 declaration here... }); Sometimes this is a common problem!

0
source

Source: https://habr.com/ru/post/1245664/


All Articles