Reputation: 2265
I am using Yii2 framework with a select2 component that can let choose its color and show a sample:
$("#idColor").on("change", function() {
showSample();
});
Also I have a button to reset the Color select2 component:
$("#idReset").click(function() {
$("#idColor").val(null).trigger("change");
});
But when I click the Reset button the showSample() function is called. I only need to clear the selected value of Color.
Upvotes: 0
Views: 1500
Reputation: 1165
Try This:
$("#idReset").click(function() {
$("#idColor").select2("val",null);
});
This will change the value of select2 dropdown without triggering change event.
Created jsFiddle for the same http://jsfiddle.net/fyhsz9ra/1733/.
Upvotes: 1