@@ -272,7 +272,8 @@ the specific language governing permissions and limitations under the Apache Lic
272272
273273 /* make sure el received focus so we do not error out when trying to manipulate the caret.
274274 sometimes modals or others listeners may steal it after its set */
275- if ( $el . is ( ":visible" ) && el === document . activeElement ) {
275+ var isVisible = ( el . offsetWidth > 0 || el . offsetHeight > 0 ) ;
276+ if ( isVisible && el === document . activeElement ) {
276277
277278 /* after the focus is set move the caret to the end, necessary when we val()
278279 just before setting focus */
@@ -1454,7 +1455,7 @@ the specific language governing permissions and limitations under the Apache Lic
14541455
14551456 // abstract
14561457 findHighlightableChoices : function ( ) {
1457- return this . results . find ( ".select2-result-selectable:not(.select2-disabled, .select2-selected)" ) ;
1458+ return this . results . find ( ".select2-result-selectable:not(.select2-disabled):not( .select2-selected)" ) ;
14581459 } ,
14591460
14601461 // abstract
@@ -2258,21 +2259,29 @@ the specific language governing permissions and limitations under the Apache Lic
22582259
22592260 // single
22602261 postprocessResults : function ( data , initial , noHighlightUpdate ) {
2261- var selected = 0 , self = this , showSearchInput = true ;
2262+ var selected = 0 , selectedElm = null , self = this , showSearchInput = true ;
22622263
22632264 // find the selected element in the result list
22642265
22652266 this . findHighlightableChoices ( ) . each2 ( function ( i , elm ) {
22662267 if ( equal ( self . id ( elm . data ( "select2-data" ) ) , self . opts . element . val ( ) ) ) {
22672268 selected = i ;
2269+ selectedElm = elm ;
22682270 return false ;
22692271 }
22702272 } ) ;
22712273
22722274 // and highlight it
22732275 if ( noHighlightUpdate !== false ) {
22742276 if ( initial === true && selected >= 0 ) {
2275- this . highlight ( selected ) ;
2277+ // By default, the selected item is displayed inside the result list from a single select
2278+ // User can provide an implementation for 'hideSelectionFromResult' and hide it
2279+ if ( this . opts . hideSelectionFromResult !== undefined && selectedElm !== null ) {
2280+ if ( this . opts . hideSelectionFromResult ( selectedElm ) )
2281+ selectedElm . addClass ( "select2-selected" ) ;
2282+ }
2283+ else
2284+ this . highlight ( selected ) ;
22762285 } else {
22772286 this . highlight ( 0 ) ;
22782287 }
@@ -2996,9 +3005,14 @@ the specific language governing permissions and limitations under the Apache Lic
29963005 choices . each2 ( function ( i , choice ) {
29973006 var id = self . id ( choice . data ( "select2-data" ) ) ;
29983007 if ( indexOf ( id , val ) >= 0 ) {
2999- choice . addClass ( "select2-selected" ) ;
3000- // mark all children of the selected parent as selected
3001- choice . find ( ".select2-result-selectable" ) . addClass ( "select2-selected" ) ;
3008+ // By default, the selected item is hidden from the result list inside a multi select
3009+ // User can provide an implementation for 'hideSelectionFromResult' and allow the same
3010+ // element to be selected multiple times.
3011+ if ( self . opts . hideSelectionFromResult === undefined || self . opts . hideSelectionFromResult ( choice ) ) {
3012+ choice . addClass ( "select2-selected" ) ;
3013+ // mark all children of the selected parent as selected
3014+ choice . find ( ".select2-result-selectable" ) . addClass ( "select2-selected" ) ;
3015+ }
30023016 }
30033017 } ) ;
30043018
@@ -3315,7 +3329,11 @@ the specific language governing permissions and limitations under the Apache Lic
33153329 adaptContainerCssClass : function ( c ) { return c ; } ,
33163330 adaptDropdownCssClass : function ( c ) { return null ; } ,
33173331 nextSearchTerm : function ( selectedObject , currentSearchTerm ) { return undefined ; } ,
3332+ << < << << HEAD
33183333 searchInputPlaceholder: ''
3334+ === = ===
3335+ hideSelectionFromResult : function ( selectedObject ) { return undefined ; }
3336+ >>> > >>> master
33193337 } ;
33203338
33213339 $ . fn . select2 . ajaxDefaults = {
0 commit comments