I've tried to capture select2:clearing
event
$("#my-select").on("select2:clearing", function (e) {
console.log('cleared');
});
(jsfiddle)
but it is not fired. I've also tried other versions (like select2:removed
etc., see another question with similar problem), but it also doesn't work.
I use select2 4.0.0-beta2.
New options can be added to a Select2 control programmatically by creating a new Javascript Option object and appending it to the control: var data = { id: 1, text: 'Barn owl' }; var newOption = new Option(data.text, data.id, false, false); $('#mySelect2').append(newOption).trigger('change');
Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.
The changelog of select2 4.0.0-beta2 states:
Removed events
select2-clearing - Use select2:unselecting instead
https://github.com/select2/select2/releases
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