From 08b75a1798cfa3bdccef6c08defd6ee9f4ff897b Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 21 Feb 2013 10:53:16 +0100 Subject: [PATCH] Do not trigger event when calling clear() from val() with empty value --- select2.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index 4a4b3879..3921f2f7 100644 --- a/select2.js +++ b/select2.js @@ -1747,7 +1747,7 @@ the specific language governing permissions and limitations under the Apache Lic }, // single - clear: function() { + clear: function(triggerChange) { var data=this.selection.data("select2-data"); if (data) { // guard against queued quick consecutive clicks this.opts.element.val(""); @@ -1755,8 +1755,10 @@ the specific language governing permissions and limitations under the Apache Lic this.selection.removeData("select2-data"); this.setPlaceholder(); - this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); - this.triggerChange({removed:data}); + if (triggerChange !== false){ + this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); + this.triggerChange({removed:data}); + } } }, @@ -1946,7 +1948,7 @@ the specific language governing permissions and limitations under the Apache Lic } // val is an id. !val is true for [undefined,null,'',0] - 0 is legal if (!val && val !== 0) { - this.clear(); + this.clear(triggerChange); if (triggerChange) { this.triggerChange(); }