From dc27a5b74d78c1f04306caba576c27973311424b Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 9 Apr 2013 19:53:11 -0700 Subject: [PATCH] add a rejectable select event. fixes #1053 --- select2.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/select2.js b/select2.js index d0727091..bab0f084 100644 --- a/select2.js +++ b/select2.js @@ -964,6 +964,13 @@ the specific language governing permissions and limitations under the Apache Lic } }, + // abstract + triggerSelect: function(data) { + var evt = $.Event("selected", { val: this.id(data), object: data }); + this.opts.element.trigger(evt); + return !evt.isDefaultPrevented(); + }, + /** * Triggers the change event on the source element */ @@ -1974,6 +1981,9 @@ the specific language governing permissions and limitations under the Apache Lic // single onSelect: function (data, options) { + + if (!this.triggerSelect(data)) { return; } + var old = this.opts.element.val(), oldData = this.data(); @@ -2407,6 +2417,9 @@ the specific language governing permissions and limitations under the Apache Lic // multi onSelect: function (data, options) { + + if (!this.triggerSelect(data)) { return; } + this.addSelectedChoice(data); this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });