Reset select2 value and show placeholder
Select2 has changed their API:
Select2: The
select2("val")
method has been deprecated and will be removed in later Select2 versions. Use $element.val() instead.
The best way to do this now is:
$('#your_select_input').val('');
Edit: December 2016 Comments suggest that the below is the updated way to do this:
$('#your_select_input').val([]);
The accepted answer does not work in my case. I'm trying this, and it's working:
Define select2:
$("#customers_select").select2({
placeholder: "Select a State",
allowClear: true
});
or
$("#customers_select").select2({
placeholder: "Select a State"
});
To reset:
$("#customers_select").val('').trigger('change')
or
$("#customers_select").empty().trigger('change')
You must define the select2 as
$("#customers_select").select2({
placeholder: "Select a customer",
initSelection: function(element, callback) {
}
});
To reset the select2
$("#customers_select").select2("val", "");
The only thing can work for me is:
$('select2element').val(null).trigger("change")
I'm using version 4.0.3
Reference
According to Select2 Documentation