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

Create locked items that can't be removed.

This patch creates multi select items that can't be removed.
This commit is contained in:
Todd Rafferty 2012-10-16 14:33:35 -03:00
parent 6e3b7097a3
commit 43939f08a4

View File

@ -1838,7 +1838,7 @@ the specific language governing permissions and limitations under the Apache Lic
return; return;
} }
choices = selection.find(".select2-search-choice"); choices = selection.find(".select2-search-choice:not(.select2-locked)");
if (choices.length > 0) { if (choices.length > 0) {
choices.last().addClass("select2-search-choice-focus"); choices.last().addClass("select2-search-choice-focus");
} }
@ -2069,38 +2069,46 @@ the specific language governing permissions and limitations under the Apache Lic
this.focusSearch(); this.focusSearch();
}, },
// multi
addSelectedChoice: function (data) { addSelectedChoice: function (data) {
var choice=$( var enableChoice = !data.disabled,
enabledItem = $(
"<li class='select2-search-choice'>" + "<li class='select2-search-choice'>" +
" <div></div>" + " <div></div>" +
" <a href='javascript:void(0)' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" + " <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
"</li>"), "</li>"),
disabledItem = $(
"<li class='select2-search-choice select2-locked'>" +
"<div></div>" +
"</li>");
var choice = enableChoice ? enabledItem : disabledItem,
id = this.id(data), id = this.id(data),
val = this.getVal(), val = this.getVal(),
formatted; formatted;
formatted=this.opts.formatSelection(data, choice.find("div")); formatted=this.opts.formatSelection(data, choice.find("div"));
if (formatted != undefined) { if (formatted != undefined) {
choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>"); choice.find("div").replaceWith("<div>"+this.opts.escapeMarkup(formatted)+"</div>");
} }
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(){ if(enableChoice){
this.unselect($(e.target)); choice.find(".select2-search-choice-close")
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"); .bind("mousedown", killEvent)
this.close(); .bind("click dblclick", this.bind(function (e) {
this.focusSearch(); if (!this.enabled) return;
})).dequeue();
killEvent(e); $(e.target).closest(".select2-search-choice").fadeOut('fast', this.bind(function(){
})).bind("focus", this.bind(function () { this.unselect($(e.target));
if (!this.enabled) return; this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
this.container.addClass("select2-container-active"); this.close();
this.dropdown.addClass("select2-drop-active"); 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.data("select2-data", data);
choice.insertBefore(this.searchContainer); choice.insertBefore(this.searchContainer);