@@ -1838,7 +1838,7 @@ the specific language governing permissions and limitations under the Apache Lic
18381838 return ;
18391839 }
18401840
1841- choices = selection . find ( ".select2-search-choice" ) ;
1841+ choices = selection . find ( ".select2-search-choice:not(.select2-locked) " ) ;
18421842 if ( choices . length > 0 ) {
18431843 choices . last ( ) . addClass ( "select2-search-choice-focus" ) ;
18441844 }
@@ -2069,38 +2069,46 @@ the specific language governing permissions and limitations under the Apache Lic
20692069 this . focusSearch ( ) ;
20702070 } ,
20712071
2072- // multi
20732072 addSelectedChoice : function ( data ) {
2074- var choice = $ (
2073+ var enableChoice = ! data . disabled ,
2074+ enabledItem = $ (
20752075 "<li class='select2-search-choice'>" +
20762076 " <div></div>" +
2077- " <a href='javascript:void(0) ' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
2077+ " <a href='# ' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a>" +
20782078 "</li>" ) ,
2079+ disabledItem = $ (
2080+ "<li class='select2-search-choice select2-locked'>" +
2081+ "<div></div>" +
2082+ "</li>" ) ;
2083+ var choice = enableChoice ? enabledItem : disabledItem ,
20792084 id = this . id ( data ) ,
20802085 val = this . getVal ( ) ,
20812086 formatted ;
2082-
2087+
20832088 formatted = this . opts . formatSelection ( data , choice . find ( "div" ) ) ;
20842089 if ( formatted != undefined ) {
20852090 choice . find ( "div" ) . replaceWith ( "<div>" + this . opts . escapeMarkup ( formatted ) + "</div>" ) ;
20862091 }
2087- choice . find ( ".select2-search-choice-close" )
2088- . bind ( "mousedown" , killEvent )
2089- . bind ( "click dblclick" , this . bind ( function ( e ) {
2090- if ( ! this . enabled ) return ;
20912092
2092- $ ( e . target ) . closest ( ".select2-search-choice" ) . fadeOut ( 'fast' , this . bind ( function ( ) {
2093- this . unselect ( $ ( e . target ) ) ;
2094- this . selection . find ( ".select2-search-choice-focus" ) . removeClass ( "select2-search-choice-focus" ) ;
2095- this . close ( ) ;
2096- this . focusSearch ( ) ;
2097- } ) ) . dequeue ( ) ;
2098- killEvent ( e ) ;
2099- } ) ) . bind ( "focus" , this . bind ( function ( ) {
2100- if ( ! this . enabled ) return ;
2101- this . container . addClass ( "select2-container-active" ) ;
2102- this . dropdown . addClass ( "select2-drop-active" ) ;
2103- } ) ) ;
2093+ if ( enableChoice ) {
2094+ choice . find ( ".select2-search-choice-close" )
2095+ . bind ( "mousedown" , killEvent )
2096+ . bind ( "click dblclick" , this . bind ( function ( e ) {
2097+ if ( ! this . enabled ) return ;
2098+
2099+ $ ( e . target ) . closest ( ".select2-search-choice" ) . fadeOut ( 'fast' , this . bind ( function ( ) {
2100+ this . unselect ( $ ( e . target ) ) ;
2101+ this . selection . find ( ".select2-search-choice-focus" ) . removeClass ( "select2-search-choice-focus" ) ;
2102+ this . close ( ) ;
2103+ this . focusSearch ( ) ;
2104+ } ) ) . dequeue ( ) ;
2105+ killEvent ( e ) ;
2106+ } ) ) . bind ( "focus" , this . bind ( function ( ) {
2107+ if ( ! this . enabled ) return ;
2108+ this . container . addClass ( "select2-container-active" ) ;
2109+ this . dropdown . addClass ( "select2-drop-active" ) ;
2110+ } ) ) ;
2111+ }
21042112
21052113 choice . data ( "select2-data" , data ) ;
21062114 choice . insertBefore ( this . searchContainer ) ;
0 commit comments