Update to unselect method to support "select2-removing" triggers.
The goal here is send off a triggered event to a subscriber that an element is going to be removed. It hasn't removed yet but would be after the event fires. I have also added logic to determine if a subscriber has prevented default. This will prove useful in the future if a subscriber needs to extend the functionality for other usages.
This commit is contained in:
parent
f39ab3080e
commit
204d4a276e
10
select2.js
10
select2.js
@ -2855,7 +2855,15 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.setVal(val);
|
this.setVal(val);
|
||||||
if (this.select) this.postprocessResults();
|
if (this.select) this.postprocessResults();
|
||||||
}
|
}
|
||||||
selected.remove();
|
|
||||||
|
var evt = $.Event("select2-removing");
|
||||||
|
evt.val = this.id(data);
|
||||||
|
evt.choice = data;
|
||||||
|
this.opts.element.trigger(evt);
|
||||||
|
|
||||||
|
if (evt.isDefaultPrevented()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
|
this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
|
||||||
this.triggerChange({ removed: data });
|
this.triggerChange({ removed: data });
|
||||||
|
Loading…
Reference in New Issue
Block a user