1
0
mirror of synced 2024-11-26 14:56:07 +03:00

added selected and removed events. fixes #835

This commit is contained in:
Igor Vaynberg 2013-02-09 16:44:44 -08:00
parent d54378563c
commit a4c76f2dfb

View File

@ -1733,10 +1733,13 @@ the specific language governing permissions and limitations under the Apache Lic
// single // single
clear: function() { clear: function() {
var data=this.selection.data("select2-data");
this.opts.element.val(""); this.opts.element.val("");
this.selection.find("span").empty(); this.selection.find("span").empty();
this.selection.removeData("select2-data"); this.selection.removeData("select2-data");
this.setPlaceholder(); this.setPlaceholder();
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
}, },
/** /**
@ -1848,6 +1851,8 @@ the specific language governing permissions and limitations under the Apache Lic
if (!options || !options.noFocus) if (!options || !options.noFocus)
this.selection.focus(); this.selection.focus();
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
if (!equal(old, this.id(data))) { this.triggerChange(); } if (!equal(old, this.id(data))) { this.triggerChange(); }
}, },
@ -2250,6 +2255,8 @@ 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 // 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 // added we do not need to check if this is a new element before firing change
this.triggerChange({ added: data }); this.triggerChange({ added: data });
@ -2340,6 +2347,9 @@ the specific language governing permissions and limitations under the Apache Lic
if (this.select) this.postprocessResults(); if (this.select) this.postprocessResults();
} }
selected.remove(); selected.remove();
this.opts.element.trigger({ type: "removed", val: this.id(data), choice: data });
this.triggerChange({ removed: data }); this.triggerChange({ removed: data });
}, },