1
0
mirror of synced 2024-11-26 06:46:04 +03:00

Merge pull request #2160 from s7anley/bugfix/2073-select2-removing

Multiselect items are not removed when event is prevented
This commit is contained in:
Kevin Brown 2014-03-07 10:12:01 -05:00
commit 51e5d436ff

View File

@ -2610,13 +2610,15 @@ the specific language governing permissions and limitations under the Apache Lic
selectedChoice = next.length ? next : null; selectedChoice = next.length ? next : null;
} }
else if (e.which === KEY.BACKSPACE) { else if (e.which === KEY.BACKSPACE) {
this.unselect(selected.first()); if (this.unselect(selected.first())) {
this.search.width(10); this.search.width(10);
selectedChoice = prev.length ? prev : next; selectedChoice = prev.length ? prev : next;
}
} else if (e.which == KEY.DELETE) { } else if (e.which == KEY.DELETE) {
this.unselect(selected.first()); if (this.unselect(selected.first())) {
this.search.width(10); this.search.width(10);
selectedChoice = next.length ? next : null; selectedChoice = next.length ? next : null;
}
} else if (e.which == KEY.ENTER) { } else if (e.which == KEY.ENTER) {
selectedChoice = null; selectedChoice = null;
} }
@ -2948,13 +2950,11 @@ the specific language governing permissions and limitations under the Apache Lic
.on("click dblclick", this.bind(function (e) { .on("click dblclick", this.bind(function (e) {
if (!this.isInterfaceEnabled()) return; if (!this.isInterfaceEnabled()) return;
$(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
this.unselect($(e.target)); this.unselect($(e.target));
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"); this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
killEvent(e);
this.close(); this.close();
this.focusSearch(); this.focusSearch();
})).dequeue();
killEvent(e);
})).on("focus", this.bind(function () { })).on("focus", this.bind(function () {
if (!this.isInterfaceEnabled()) return; if (!this.isInterfaceEnabled()) return;
this.container.addClass("select2-container-active"); this.container.addClass("select2-container-active");
@ -2988,25 +2988,27 @@ the specific language governing permissions and limitations under the Apache Lic
return; return;
} }
while((index = indexOf(this.id(data), val)) >= 0) {
val.splice(index, 1);
this.setVal(val);
if (this.select) this.postprocessResults();
}
var evt = $.Event("select2-removing"); var evt = $.Event("select2-removing");
evt.val = this.id(data); evt.val = this.id(data);
evt.choice = data; evt.choice = data;
this.opts.element.trigger(evt); this.opts.element.trigger(evt);
if (evt.isDefaultPrevented()) { if (evt.isDefaultPrevented()) {
return; return false;
}
while((index = indexOf(this.id(data), val)) >= 0) {
val.splice(index, 1);
this.setVal(val);
if (this.select) this.postprocessResults();
} }
selected.remove(); selected.remove();
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 });
return true;
}, },
// multi // multi