Skip to content

Commit 596cf52

Browse files
committed
Merge pull request select2#2070 from jeanmonod/master
Allow to display item created by createSearchChoice at the end of the dropdown
2 parents fb6e863 + ed77cab commit 596cf52

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

select2.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,16 @@ the specific language governing permissions and limitations under the Apache Lic
10141014
throw "query function not defined for Select2 " + opts.element.attr("id");
10151015
}
10161016

1017+
if (opts.createSearchChoicePosition === 'top') {
1018+
opts.createSearchChoicePosition = function(list, item) { list.unshift(item); };
1019+
}
1020+
else if (opts.createSearchChoicePosition === 'bottom') {
1021+
opts.createSearchChoicePosition = function(list, item) { list.push(item); };
1022+
}
1023+
else if (typeof(opts.createSearchChoicePosition) !== "function") {
1024+
throw "invalid createSearchChoicePosition option must be 'top', 'bottom' or a custom function";
1025+
}
1026+
10171027
return opts;
10181028
},
10191029

@@ -1694,7 +1704,7 @@ the specific language governing permissions and limitations under the Apache Lic
16941704
function () {
16951705
return equal(self.id(this), self.id(def));
16961706
}).length === 0) {
1697-
data.results.unshift(def);
1707+
this.opts.createSearchChoicePosition(data.results, def);
16981708
}
16991709
}
17001710
}
@@ -3330,7 +3340,8 @@ the specific language governing permissions and limitations under the Apache Lic
33303340
adaptDropdownCssClass: function(c) { return null; },
33313341
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
33323342
hideSelectionFromResult: function(selectedObject) { return undefined; },
3333-
searchInputPlaceholder: ''
3343+
searchInputPlaceholder: '',
3344+
createSearchChoicePosition: 'top'
33343345
};
33353346

33363347
$.fn.select2.ajaxDefaults = {

0 commit comments

Comments
 (0)