From 8e9e65f8640e8af3b4bf9aba01cc9bfcdaa76dda Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Wed, 20 Feb 2013 18:35:55 -0800 Subject: [PATCH] Error when clearing a single-select box multiple times. fix #908 --- select2.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index 99edc4e8..1930377a 100644 --- a/select2.js +++ b/select2.js @@ -1749,13 +1749,15 @@ the specific language governing permissions and limitations under the Apache Lic // single clear: function() { var data=this.selection.data("select2-data"); - this.opts.element.val(""); - this.selection.find("span").empty(); - this.selection.removeData("select2-data"); - this.setPlaceholder(); + if (data) { // guard against queued quick consecutive clicks + this.opts.element.val(""); + this.selection.find("span").empty(); + this.selection.removeData("select2-data"); + this.setPlaceholder(); - this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); - this.triggerChange({removed:data}); + this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); + this.triggerChange({removed:data}); + } }, /**