From 2059b5d4d3c2b23229a2f2f7d9b4a6b353c0fa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Ko=C5=A1=C4=8Do?= <3k.stanley@gmail.com> Date: Wed, 5 Mar 2014 10:55:42 +0100 Subject: [PATCH 1/3] Unselected item is returned as options only if event isn't prevented --- select2.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index ec8af72c..11e30516 100644 --- a/select2.js +++ b/select2.js @@ -2988,12 +2988,6 @@ 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; @@ -3003,6 +2997,12 @@ 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(); + } + selected.remove(); this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data }); From 86a9c79b04084e01fb156cc25a0b0cd6dade6137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Ko=C5=A1=C4=8Do?= <3k.stanley@gmail.com> Date: Wed, 5 Mar 2014 11:00:45 +0100 Subject: [PATCH 2/3] Removed unnecessary animation during unseint multiselect by close button --- select2.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/select2.js b/select2.js index 11e30516..72de1900 100644 --- a/select2.js +++ b/select2.js @@ -2948,13 +2948,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"); From f3c6d6d51fece129597f14ac9f12cdb6177918d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Ko=C5=A1=C4=8Do?= <3k.stanley@gmail.com> Date: Wed, 5 Mar 2014 11:20:07 +0100 Subject: [PATCH 3/3] After prevented removing of item in multiselect, proper item is focused --- select2.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/select2.js b/select2.js index 72de1900..e31bf324 100644 --- a/select2.js +++ b/select2.js @@ -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; } @@ -2992,7 +2994,7 @@ the specific language governing permissions and limitations under the Apache Lic this.opts.element.trigger(evt); if (evt.isDefaultPrevented()) { - return; + return false; } while((index = indexOf(this.id(data), val)) >= 0) { @@ -3005,6 +3007,8 @@ the specific language governing permissions and limitations under the Apache Lic this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data }); this.triggerChange({ removed: data }); + + return true; }, // multi