From 6c9aef4bb3a3596408d703c03f8d26bf91c08689 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 9 Feb 2013 19:13:21 -0800 Subject: [PATCH] fire selected before close. #835 --- select2.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index acfb389c..acad1d09 100644 --- a/select2.js +++ b/select2.js @@ -1846,13 +1846,14 @@ the specific language governing permissions and limitations under the Apache Lic this.opts.element.val(this.id(data)); this.updateSelection(data); + + this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data }); + this.close(); 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(); } }, @@ -2233,6 +2234,8 @@ the specific language governing permissions and limitations under the Apache Lic onSelect: function (data, options) { this.addSelectedChoice(data); + this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data }); + if (this.select || !this.opts.closeOnSelect) this.postprocessResults(); if (this.opts.closeOnSelect) { @@ -2255,8 +2258,6 @@ 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 });