@@ -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