Merge pull request #2070 from jeanmonod/master
Allow to display item created by createSearchChoice at the end of the dropdown
This commit is contained in:
commit
596cf52d07
15
select2.js
15
select2.js
@ -1014,6 +1014,16 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
throw "query function not defined for Select2 " + opts.element.attr("id");
|
throw "query function not defined for Select2 " + opts.element.attr("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.createSearchChoicePosition === 'top') {
|
||||||
|
opts.createSearchChoicePosition = function(list, item) { list.unshift(item); };
|
||||||
|
}
|
||||||
|
else if (opts.createSearchChoicePosition === 'bottom') {
|
||||||
|
opts.createSearchChoicePosition = function(list, item) { list.push(item); };
|
||||||
|
}
|
||||||
|
else if (typeof(opts.createSearchChoicePosition) !== "function") {
|
||||||
|
throw "invalid createSearchChoicePosition option must be 'top', 'bottom' or a custom function";
|
||||||
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1694,7 +1704,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
function () {
|
function () {
|
||||||
return equal(self.id(this), self.id(def));
|
return equal(self.id(this), self.id(def));
|
||||||
}).length === 0) {
|
}).length === 0) {
|
||||||
data.results.unshift(def);
|
this.opts.createSearchChoicePosition(data.results, def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3330,7 +3340,8 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
adaptDropdownCssClass: function(c) { return null; },
|
adaptDropdownCssClass: function(c) { return null; },
|
||||||
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
|
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
|
||||||
hideSelectionFromResult: function(selectedObject) { return undefined; },
|
hideSelectionFromResult: function(selectedObject) { return undefined; },
|
||||||
searchInputPlaceholder: ''
|
searchInputPlaceholder: '',
|
||||||
|
createSearchChoicePosition: 'top'
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn.select2.ajaxDefaults = {
|
$.fn.select2.ajaxDefaults = {
|
||||||
|
Loading…
Reference in New Issue
Block a user