Skip to content

Commit

Permalink
Merge pull request #2160 from s7anley/bugfix/2073-select2-removing
Browse files Browse the repository at this point in the history
Multiselect items are not removed when event is prevented
  • Loading branch information
kevin-brown committed Mar 7, 2014
2 parents e6fbfcd + f3c6d6d commit 51e5d43
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions select2.js
Expand Up @@ -2610,13 +2610,15 @@ the specific language governing permissions and limitations under the Apache Lic
selectedChoice = next.length ? next : null;
}
else if (e.which === KEY.BACKSPACE) {
this.unselect(selected.first());
this.search.width(10);
selectedChoice = prev.length ? prev : next;
if (this.unselect(selected.first())) {
this.search.width(10);
selectedChoice = prev.length ? prev : next;
}
} else if (e.which == KEY.DELETE) {
this.unselect(selected.first());
this.search.width(10);
selectedChoice = next.length ? next : null;
if (this.unselect(selected.first())) {
this.search.width(10);
selectedChoice = next.length ? next : null;
}
} else if (e.which == KEY.ENTER) {
selectedChoice = null;
}
Expand Down Expand Up @@ -2948,13 +2950,11 @@ the specific language governing permissions and limitations under the Apache Lic
.on("click dblclick", this.bind(function (e) {
if (!this.isInterfaceEnabled()) return;

$(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
this.unselect($(e.target));
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
this.close();
this.focusSearch();
})).dequeue();
this.unselect($(e.target));
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
killEvent(e);
this.close();
this.focusSearch();
})).on("focus", this.bind(function () {
if (!this.isInterfaceEnabled()) return;
this.container.addClass("select2-container-active");
Expand Down Expand Up @@ -2988,25 +2988,27 @@ the specific language governing permissions and limitations under the Apache Lic
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");
evt.val = this.id(data);
evt.choice = data;
this.opts.element.trigger(evt);

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();

this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
this.triggerChange({ removed: data });

return true;
},

// multi
Expand Down

0 comments on commit 51e5d43

Please sign in to comment.