I know how to enable the selected attribute from dropdown; I can use this code :
$('select').select2();
but my problem is how to disable it ? thx
Disabling a Select2 control Select2 will respond to the disabled attribute on <select> elements. You can also initialize Select2 with disabled: true to get the same effect.
Hiding the search box For single selects, Select2 allows you to hide the search box using the minimumResultsForSearch configuration option. In this example, we use the value Infinity to tell Select2 to never display the search box.
Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.
HTML. Create a <select class="select2_el" > element to initialize select2 on page load and create <div id="elements" > container to store <select > element on button click using jQuery AJAX.
The right way for Select2 3.x is:
$('select').select2("enable", false)
This works fine.
For those using Select2 4.x, you can disable an individual option by doing:
$('select option:selected').prop('disabled', true);
For those using Select2 4.x, you can disable the entire dropdown with:
$('select').prop('disabled', true);
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