Skip to content

Commit dc27a5b

Browse files
committed
add a rejectable select event. fixes select2#1053
1 parent 931862c commit dc27a5b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

select2.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,13 @@ the specific language governing permissions and limitations under the Apache Lic
964964
}
965965
},
966966

967+
// abstract
968+
triggerSelect: function(data) {
969+
var evt = $.Event("selected", { val: this.id(data), object: data });
970+
this.opts.element.trigger(evt);
971+
return !evt.isDefaultPrevented();
972+
},
973+
967974
/**
968975
* Triggers the change event on the source element
969976
*/
@@ -1974,6 +1981,9 @@ the specific language governing permissions and limitations under the Apache Lic
19741981

19751982
// single
19761983
onSelect: function (data, options) {
1984+
1985+
if (!this.triggerSelect(data)) { return; }
1986+
19771987
var old = this.opts.element.val(),
19781988
oldData = this.data();
19791989

@@ -2407,6 +2417,9 @@ the specific language governing permissions and limitations under the Apache Lic
24072417

24082418
// multi
24092419
onSelect: function (data, options) {
2420+
2421+
if (!this.triggerSelect(data)) { return; }
2422+
24102423
this.addSelectedChoice(data);
24112424

24122425
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });

0 commit comments

Comments
 (0)