From edc0d86fd25ecdddde7059bf2b41dba20aab0fa7 Mon Sep 17 00:00:00 2001 From: Duncan Smart Date: Fri, 30 Aug 2013 20:31:16 +0100 Subject: [PATCH] Added `select2-clearing` event that allows clearing selection to be canceled. --- select2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/select2.js b/select2.js index 593e1865..3e9c929d 100644 --- a/select2.js +++ b/select2.js @@ -2044,6 +2044,11 @@ the specific language governing permissions and limitations under the Apache Lic clear: function(triggerChange) { var data=this.selection.data("select2-data"); 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(); this.opts.element.val(placeholderOption ? placeholderOption.val() : ""); this.selection.find(".select2-chosen").empty();