1
0
mirror of synced 2024-11-26 14:56:07 +03:00

Added select2-clearing event

that allows clearing selection to be canceled.
This commit is contained in:
Duncan Smart 2013-08-30 20:31:16 +01:00
parent ca7550bf4d
commit edc0d86fd2

View File

@ -2044,6 +2044,11 @@ the specific language governing permissions and limitations under the Apache Lic
clear: function(triggerChange) { clear: function(triggerChange) {
var data=this.selection.data("select2-data"); var data=this.selection.data("select2-data");
if (data) { // guard against queued quick consecutive clicks if (data) { // guard against queued quick consecutive clicks
var evt = $.Event("select2-clearing");
this.opts.element.trigger(evt);
if (evt.isDefaultPrevented()) {
return;
}
var placeholderOption = this.getPlaceholderOption(); var placeholderOption = this.getPlaceholderOption();
this.opts.element.val(placeholderOption ? placeholderOption.val() : ""); this.opts.element.val(placeholderOption ? placeholderOption.val() : "");
this.selection.find(".select2-chosen").empty(); this.selection.find(".select2-chosen").empty();