Say we have a simple select2
list:
<select id="e1"> <option value="AL">Alabama</option> ... <option value="WY">Wyoming</option> </select>
Initiated like:
$("#e1").select2();
How can I remove select2
and return it to a regular dropdown? I can't find any examples or entry in documentation.
Something like:
$("#e1").select2('remove');
would be nice.
In order to enable or disable Select2, you should call . prop('disabled', true/false) on the element. Support for the old methods will be completely removed in Select2 4.1.
This behaviour exists not because Select2 is forcing it, but because the browser is auto-selecting the first option for you. We can't control that, we can only work around it. Your best option is to use the placeholder support in Select2 and include a blank option tag as your default selection.
In order to hide the search box in select2, you can hide the search box by setting "minimumResultsForSearch" to a negative value. $('select'). select2({ minimumResultsForSearch: -1 });
select2:open is fired whenever the dropdown is opened. select2:opening is fired before this and can be prevented. select2:close is fired whenever the dropdown is closed. select2:closing is fired before this and can be prevented.
You need to use destroy
method on select2. See the Documentation
i.e
$("#e1").select2('destroy');
That work for me!
var $select = $('.select2').select2(); //console.log($select); $select.each(function(i,item){ //console.log(item); $(item).select2("destroy"); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With