Skip to content

Commit 6c9aef4

Browse files
committed
fire selected before close. select2#835
1 parent a4c76f2 commit 6c9aef4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

select2.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,13 +1846,14 @@ the specific language governing permissions and limitations under the Apache Lic
18461846

18471847
this.opts.element.val(this.id(data));
18481848
this.updateSelection(data);
1849+
1850+
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
1851+
18491852
this.close();
18501853

18511854
if (!options || !options.noFocus)
18521855
this.selection.focus();
18531856

1854-
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
1855-
18561857
if (!equal(old, this.id(data))) { this.triggerChange(); }
18571858
},
18581859

@@ -2233,6 +2234,8 @@ the specific language governing permissions and limitations under the Apache Lic
22332234
onSelect: function (data, options) {
22342235
this.addSelectedChoice(data);
22352236

2237+
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
2238+
22362239
if (this.select || !this.opts.closeOnSelect) this.postprocessResults();
22372240

22382241
if (this.opts.closeOnSelect) {
@@ -2255,8 +2258,6 @@ the specific language governing permissions and limitations under the Apache Lic
22552258
}
22562259
}
22572260

2258-
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
2259-
22602261
// since its not possible to select an element that has already been
22612262
// added we do not need to check if this is a new element before firing change
22622263
this.triggerChange({ added: data });

0 commit comments

Comments
 (0)