Merge pull request #2053 from jdecuyper/feature-hide-selection-from-result
Add hideSelectionFromResult function
This commit is contained in:
commit
cd92405312
18
select2.js
18
select2.js
@ -2257,13 +2257,14 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
|
||||
// single
|
||||
postprocessResults: function (data, initial, noHighlightUpdate) {
|
||||
var selected = 0, self = this, showSearchInput = true;
|
||||
var selected = 0, selectedElm = null, self = this, showSearchInput = true;
|
||||
|
||||
// find the selected element in the result list
|
||||
|
||||
this.findHighlightableChoices().each2(function (i, elm) {
|
||||
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
|
||||
selected = i;
|
||||
selectedElm = elm;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@ -2271,6 +2272,13 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
// and highlight it
|
||||
if (noHighlightUpdate !== false) {
|
||||
if (initial === true && selected >= 0) {
|
||||
// By default, the selected item is displayed inside the result list from a single select
|
||||
// User can provide an implementation for 'hideSelectionFromResult' and hide it
|
||||
if(this.opts.hideSelectionFromResult !== undefined && selectedElm !== null) {
|
||||
if(this.opts.hideSelectionFromResult(selectedElm))
|
||||
selectedElm.addClass("select2-selected");
|
||||
}
|
||||
else
|
||||
this.highlight(selected);
|
||||
} else {
|
||||
this.highlight(0);
|
||||
@ -2995,10 +3003,15 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
choices.each2(function (i, choice) {
|
||||
var id = self.id(choice.data("select2-data"));
|
||||
if (indexOf(id, val) >= 0) {
|
||||
// By default, the selected item is hidden from the result list inside a multi select
|
||||
// User can provide an implementation for 'hideSelectionFromResult' and allow the same
|
||||
// element to be selected multiple times.
|
||||
if(self.opts.hideSelectionFromResult === undefined || self.opts.hideSelectionFromResult(choice)) {
|
||||
choice.addClass("select2-selected");
|
||||
// mark all children of the selected parent as selected
|
||||
choice.find(".select2-result-selectable").addClass("select2-selected");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
compound.each2(function(i, choice) {
|
||||
@ -3313,7 +3326,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
||||
selectOnBlur: false,
|
||||
adaptContainerCssClass: function(c) { return c; },
|
||||
adaptDropdownCssClass: function(c) { return null; },
|
||||
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; }
|
||||
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
|
||||
hideSelectionFromResult: function(selectedObject) { return undefined; }
|
||||
};
|
||||
|
||||
$.fn.select2.ajaxDefaults = {
|
||||
|
Loading…
Reference in New Issue
Block a user