From 43939f08a4b00556d83ed02f8680b612f95af524 Mon Sep 17 00:00:00 2001 From: Todd Rafferty Date: Tue, 16 Oct 2012 14:33:35 -0300 Subject: [PATCH 1/3] Create locked items that can't be removed. This patch creates multi select items that can't be removed. --- select2.js | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/select2.js b/select2.js index 27385008..8d26fe23 100644 --- a/select2.js +++ b/select2.js @@ -1838,7 +1838,7 @@ the specific language governing permissions and limitations under the Apache Lic return; } - choices = selection.find(".select2-search-choice"); + choices = selection.find(".select2-search-choice:not(.select2-locked)"); if (choices.length > 0) { choices.last().addClass("select2-search-choice-focus"); } @@ -2069,38 +2069,46 @@ the specific language governing permissions and limitations under the Apache Lic this.focusSearch(); }, - // multi addSelectedChoice: function (data) { - var choice=$( + var enableChoice = !data.disabled, + enabledItem = $( "
  • " + "
    " + - " " + + " " + "
  • "), + disabledItem = $( + "
  • " + + "
    " + + "
  • "); + var choice = enableChoice ? enabledItem : disabledItem, id = this.id(data), val = this.getVal(), formatted; - + formatted=this.opts.formatSelection(data, choice.find("div")); if (formatted != undefined) { choice.find("div").replaceWith("
    "+this.opts.escapeMarkup(formatted)+"
    "); } - choice.find(".select2-search-choice-close") - .bind("mousedown", killEvent) - .bind("click dblclick", this.bind(function (e) { - if (!this.enabled) 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(); - killEvent(e); - })).bind("focus", this.bind(function () { - if (!this.enabled) return; - this.container.addClass("select2-container-active"); - this.dropdown.addClass("select2-drop-active"); - })); + if(enableChoice){ + choice.find(".select2-search-choice-close") + .bind("mousedown", killEvent) + .bind("click dblclick", this.bind(function (e) { + if (!this.enabled) 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(); + killEvent(e); + })).bind("focus", this.bind(function () { + if (!this.enabled) return; + this.container.addClass("select2-container-active"); + this.dropdown.addClass("select2-drop-active"); + })); + } choice.data("select2-data", data); choice.insertBefore(this.searchContainer); From d382f3cdb55ca8aa92c2a353af917a8f477272f9 Mon Sep 17 00:00:00 2001 From: Todd Rafferty Date: Tue, 16 Oct 2012 14:34:55 -0300 Subject: [PATCH 2/3] Added .select2-locked --- select2.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/select2.css b/select2.css index 7ccb8d18..ff55939c 100644 --- a/select2.css +++ b/select2.css @@ -410,6 +410,10 @@ disabled look for already selected choices in the results dropdown background-image: linear-gradient(top, #eeeeee 1%, #ffffff 15%); } +.select2-locked { + padding: 3px 5px 3px 5px !important; +} + .select2-container-multi .select2-choices { min-height: 26px; } From 1d4ea633aa9e246010bc88a500baa71400f1c18d Mon Sep 17 00:00:00 2001 From: Todd Rafferty Date: Tue, 16 Oct 2012 14:41:03 -0300 Subject: [PATCH 3/3] Goofed, changed disabled to locked. --- select2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/select2.js b/select2.js index 8d26fe23..b221ac54 100644 --- a/select2.js +++ b/select2.js @@ -2070,7 +2070,7 @@ the specific language governing permissions and limitations under the Apache Lic }, addSelectedChoice: function (data) { - var enableChoice = !data.disabled, + var enableChoice = !data.locked, enabledItem = $( "
  • " + "
    " +