I see three problems:
- The display of the Select2 control does not refresh when its value changes due to the reset form.
- The All option does not have a
value attribute. - The All option is disabled.
First, I recommend using the setTimeout function to ensure that the code runs after the reset form completes.
You can execute the code at the click of a button:
$('#searchclear').click(function() { setTimeout(function() {
Or, when the form is reset:
$('form').on('reset', function() { setTimeout(function() {
How to use the code:
Since the "All" option is disabled, the reset form does not make this the selected value. Therefore, you must explicitly specify it as the selected value. The way to do this is with the Select2 function "val". And since the Everyone parameter does not have a value attribute, its value matches its text, which is All. Therefore, you should use the code indicated by thtsigma in the selected answer:
$("#d").select2('val', 'All');
If the value="" attribute needs to be added to the "All" option, you can use the Daniel Dener code:
$("#d").select2('val', '');
If the "All" option has not been disabled, you just need to force Select2 to be updated, in which case you could use:
$('#d').change();
Note. The following Lenart code is a way to clear the selection, but it does not invoke the All selection:
$('#d').select2('data', null)
John S Nov 08 '14 at 4:47
source share