@ -1228,7 +1228,7 @@ $.fn.dropdown = function(parameters) {
newIndex
;
// visible menu keyboard shortcuts
if ( module . is . visible ( ) ) {
if ( module . is . visible ( ) || settings . allowAdditions ) {
// enter (select or open sub-menu)
if ( pressedKey == keys . enter || delimiterPressed ) {
@ -2234,6 +2234,7 @@ $.fn.dropdown = function(parameters) {
} ,
value : function ( value , text , $selected ) {
var
escapedValue = module . escape . value ( value ) ,
hasInput = ( $input . length > 0 ) ,
isAddition = ! module . has . value ( value ) ,
currentValue = module . get . values ( ) ,
@ -2254,10 +2255,10 @@ $.fn.dropdown = function(parameters) {
module . debug ( 'Adding user option' , value ) ;
module . add . optionValue ( value ) ;
}
module . debug ( 'Updating input value' , v alue, currentValue ) ;
module . debug ( 'Updating input value' , escapedV alue, currentValue ) ;
internalChange = true ;
$input
. val ( v alue)
. val ( escapedV alue)
;
if ( settings . fireOnInit === false && module . is . initialLoad ( ) ) {
module . debug ( 'Input native change event ignored on initial load' ) ;
@ -2268,8 +2269,8 @@ $.fn.dropdown = function(parameters) {
internalChange = false ;
}
else {
module . verbose ( 'Storing value in metadata' , v alue, $input ) ;
if ( v alue !== currentValue ) {
module . verbose ( 'Storing value in metadata' , escapedV alue, $input ) ;
if ( escapedV alue !== currentValue ) {
$module . data ( metadata . value , stringValue ) ;
}
}
@ -2377,17 +2378,18 @@ $.fn.dropdown = function(parameters) {
$next = module . is . searchSelection ( )
? $search
: $text ,
escapedValue = module . escape . value ( value ) ,
$label
;
$label = $ ( '<a />' )
. addClass ( className . label )
. attr ( 'data-value' , v alue)
. html ( templates . label ( v alue, text ) )
. attr ( 'data-value' , escapedV alue)
. html ( templates . label ( escapedV alue, text ) )
;
$label = settings . onLabelCreate . call ( $label , v alue, text ) ;
$label = settings . onLabelCreate . call ( $label , escapedV alue, text ) ;
if ( module . has . label ( value ) ) {
module . debug ( 'Label already exists, skipping' , v alue) ;
module . debug ( 'Label already exists, skipping' , escapedV alue) ;
return ;
}
if ( settings . label . variation ) {
@ -2428,8 +2430,9 @@ $.fn.dropdown = function(parameters) {
} ,
optionValue : function ( value ) {
var
$option = $input . find ( 'option[value="' + value + '"]' ) ,
hasOption = ( $option . length > 0 )
escapedValue = module . escape . value ( value ) ,
$option = $input . find ( 'option[value="' + escapedValue + '"]' ) ,
hasOption = ( $option . length > 0 )
;
if ( hasOption ) {
return ;
@ -2437,14 +2440,14 @@ $.fn.dropdown = function(parameters) {
// temporarily disconnect observer
if ( selectObserver ) {
selectObserver . disconnect ( ) ;
module . verbose ( 'Temporarily disconnecting mutation observer' , v alue) ;
module . verbose ( 'Temporarily disconnecting mutation observer' , escapedV alue) ;
}
if ( module . is . single ( ) ) {
module . verbose ( 'Removing previous user addition' ) ;
$input . find ( 'option.' + className . addition ) . remove ( ) ;
}
$ ( '<option/>' )
. prop ( 'value' , v alue)
. prop ( 'value' , escapedV alue)
. addClass ( className . addition )
. html ( value )
. appendTo ( $input )
@ -2601,8 +2604,9 @@ $.fn.dropdown = function(parameters) {
} ,
optionValue : function ( value ) {
var
$option = $input . find ( 'option[value="' + value + '"]' ) ,
hasOption = ( $option . length > 0 )
escapedValue = module . escape . value ( value ) ,
$option = $input . find ( 'option[value="' + escapedValue + '"]' ) ,
hasOption = ( $option . length > 0 )
;
if ( ! hasOption || ! $option . hasClass ( className . addition ) ) {
return ;
@ -2610,10 +2614,10 @@ $.fn.dropdown = function(parameters) {
// temporarily disconnect observer
if ( selectObserver ) {
selectObserver . disconnect ( ) ;
module . verbose ( 'Temporarily disconnecting mutation observer' , value ) ;
module . verbose ( 'Temporarily disconnecting mutation observer' ) ;
}
$option . remove ( ) ;
module . verbose ( 'Removing user addition as an <option>' , v alue) ;
module . verbose ( 'Removing user addition as an <option>' , escapedV alue) ;
if ( selectObserver ) {
selectObserver . observe ( $input [ 0 ] , {
childList : true ,
@ -2814,9 +2818,10 @@ $.fn.dropdown = function(parameters) {
} ,
label : function ( value ) {
var
$labels = $module . find ( selector . label )
escapedValue = module . escape . value ( value ) ,
$labels = $module . find ( selector . label )
;
return ( $labels . filter ( '[data-value="' + v alue + '"]' ) . length > 0 ) ;
return ( $labels . filter ( '[data-value="' + escapedV alue + '"]' ) . length > 0 ) ;
} ,
maxSelections : function ( ) {
return ( settings . maxSelections && module . get . selectionCount ( ) >= settings . maxSelections ) ;
@ -3124,6 +3129,26 @@ $.fn.dropdown = function(parameters) {
} ,
escape : {
value : function ( value ) {
let
multipleValues = $ . isArray ( value ) ,
stringValue = ( typeof value === 'string' ) ,
isUnparsable = ( ! stringValue && ! multipleValues ) ,
hasQuotes = ( stringValue && value . search ( regExp . quote ) !== - 1 ) ,
values = [ ]
;
if ( ! module . has . selectInput ( ) || isUnparsable || ! hasQuotes ) {
return value ;
}
module . debug ( 'Encoding quote values for use in select' , value ) ;
if ( multipleValues ) {
$ . each ( value , function ( index , value ) {
values . push ( value . replace ( regExp . quote , '"' ) ) ;
} ) ;
return values ;
}
return value . replace ( regExp . quote , '"' ) ;
} ,
regExp : function ( text ) {
text = String ( text ) ;
return text . replace ( regExp . escape , '\\$&' ) ;
@ -3411,6 +3436,7 @@ $.fn.dropdown.settings = {
regExp : {
escape : /[-[\]{}()*+?.,\\^$|#\s]/g ,
quote : /"/g
} ,
metadata : {