From 204d4a276ec7ffad604e32aa77a782686bc2d812 Mon Sep 17 00:00:00 2001 From: Andrew Velis Date: Mon, 7 Oct 2013 20:47:12 -0700 Subject: [PATCH] Update to unselect method to support "select2-removing" triggers. The goal here is send off a triggered event to a subscriber that an element is going to be removed. It hasn't removed yet but would be after the event fires. I have also added logic to determine if a subscriber has prevented default. This will prove useful in the future if a subscriber needs to extend the functionality for other usages. --- select2.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/select2.js b/select2.js index 0fcb6118..1f59bd24 100644 --- a/select2.js +++ b/select2.js @@ -2855,7 +2855,15 @@ the specific language governing permissions and limitations under the Apache Lic this.setVal(val); if (this.select) this.postprocessResults(); } - selected.remove(); + + var evt = $.Event("select2-removing"); + evt.val = this.id(data); + evt.choice = data; + this.opts.element.trigger(evt); + + if (evt.isDefaultPrevented()) { + return; + } this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data }); this.triggerChange({ removed: data });