I\'m trying to programmatically clear a drop down using the fantastic Select2 library. The drop down is dynamically filled with a remote ajax call using the Select2 qu
Method proposed @Lelio Faieta is working for me, but because i use bootstrap theme, it remove all bootstrap settings for select2. So I used following code:
$("#remote option").remove();
I'm a little late, but this is what's working in the last version (4.0.3):
$('#select_id').val('').trigger('change');
I found the answer (compliments to user780178) I was looking for in this other question:
Reset select2 value and show placeholdler
$("#customers_select").select2("val", "");
You can use this or refer further this https://select2.org/programmatic-control/add-select-clear-items
$('#mySelect2').val(null).trigger('change');
You should use this one :
$('#remote').val(null).trigger("change");
This is the proper one, select2 will clear the selected value and show the placeholder back .
$remote.select2('data', null)