From a4c76f2dfb0b9a438c59a8a7409d2e7bf1ef16bf Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 9 Feb 2013 16:44:44 -0800 Subject: [PATCH] added selected and removed events. fixes #835 --- select2.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/select2.js b/select2.js index 6d3c22a0..acfb389c 100644 --- a/select2.js +++ b/select2.js @@ -1733,10 +1733,13 @@ 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(); + + this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); }, /** @@ -1848,6 +1851,8 @@ the specific language governing permissions and limitations under the Apache Lic if (!options || !options.noFocus) this.selection.focus(); + this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data }); + if (!equal(old, this.id(data))) { this.triggerChange(); } }, @@ -2250,6 +2255,8 @@ the specific language governing permissions and limitations under the Apache Lic } } + this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data }); + // since its not possible to select an element that has already been // added we do not need to check if this is a new element before firing change this.triggerChange({ added: data }); @@ -2340,6 +2347,9 @@ the specific language governing permissions and limitations under the Apache Lic if (this.select) this.postprocessResults(); } selected.remove(); + + this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data }); + this.triggerChange({ removed: data }); },