Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture event when allowClear option of select2 is chosen?

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.

like image 804
LA_ Avatar asked Jan 21 '15 11:01

LA_


People also ask

How do you add new option if not exist in the list using select2?

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');

What does select2 () do?

Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.


1 Answers

The changelog of select2 4.0.0-beta2 states:

Removed events

select2-clearing - Use select2:unselecting instead

https://github.com/select2/select2/releases

like image 117
Mario A Avatar answered Oct 02 '22 03:10

Mario A