change event now contains added/removed/val properties. fixes #133
This commit is contained in:
parent
050a23b53d
commit
7ec2dec955
1 changed files with 12 additions and 6 deletions
18
select2.js
18
select2.js
|
@ -692,10 +692,13 @@
|
|||
* Triggers the change event on the source element
|
||||
*/
|
||||
// abstract
|
||||
triggerChange: function () {
|
||||
// Prevents recursive triggering
|
||||
triggerChange: function (details) {
|
||||
|
||||
details = details || {};
|
||||
details= $.extend({}, details, { type: "change", val: this.val() });
|
||||
// prevents recursive triggering
|
||||
this.opts.element.data("select2-change-triggered", true);
|
||||
this.opts.element.trigger("change");
|
||||
this.opts.element.trigger(details);
|
||||
this.opts.element.data("select2-change-triggered", false);
|
||||
},
|
||||
|
||||
|
@ -1552,7 +1555,7 @@
|
|||
|
||||
// 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();
|
||||
this.triggerChange({ added: data });
|
||||
|
||||
this.focusSearch();
|
||||
},
|
||||
|
@ -1602,6 +1605,7 @@
|
|||
// multi
|
||||
unselect: function (selected) {
|
||||
var val = this.getVal(),
|
||||
data,
|
||||
index;
|
||||
|
||||
selected = selected.closest(".select2-search-choice");
|
||||
|
@ -1610,7 +1614,9 @@
|
|||
throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
|
||||
}
|
||||
|
||||
index = indexOf(this.id(selected.data("select2-data")), val);
|
||||
data = selected.data("select2-data");
|
||||
|
||||
index = indexOf(this.id(data), val);
|
||||
|
||||
if (index >= 0) {
|
||||
val.splice(index, 1);
|
||||
|
@ -1618,7 +1624,7 @@
|
|||
if (this.select) this.postprocessResults();
|
||||
}
|
||||
selected.remove();
|
||||
this.triggerChange();
|
||||
this.triggerChange({ removed: data });
|
||||
},
|
||||
|
||||
// multi
|
||||
|
|
Loading…
Add table
Reference in a new issue