File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ Selectize.defaults = {
2020 selectOnTab : true ,
2121 preload : false ,
2222 allowEmptyOption : false ,
23+ showEmptyOptionInDropdown : false ,
24+ emptyOptionLabel : '--' ,
2325 closeAfterSelect : false ,
2426
2527 scrollDuration : 60 ,
Original file line number Diff line number Diff line change @@ -139,6 +139,10 @@ $.fn.selectize = function(settings_user) {
139139 if ( ! placeholder && ! settings . allowEmptyOption ) {
140140 placeholder = $input . children ( 'option[value=""]' ) . text ( ) ;
141141 }
142+ if ( settings . allowEmptyOption && settings . showEmptyOptionInDropdown && ! $input . children ( 'option[value=""]' ) . length ) {
143+ var input_html = $input . html ( ) ;
144+ $input . html ( '<option value="">' + settings . emptyOptionLabel + '</option>' + input_html ) ;
145+ }
142146
143147 var settings_element = {
144148 'placeholder' : placeholder ,
Original file line number Diff line number Diff line change @@ -297,6 +297,7 @@ $.extend(Selectize.prototype, {
297297 setupTemplates : function ( ) {
298298 var self = this ;
299299 var field_label = self . settings . labelField ;
300+ var field_value = self . settings . valueField ;
300301 var field_optgroup = self . settings . optgroupLabelField ;
301302
302303 var templates = {
@@ -307,7 +308,7 @@ $.extend(Selectize.prototype, {
307308 return '<div class="optgroup-header">' + escape ( data [ field_optgroup ] ) + '</div>' ;
308309 } ,
309310 'option' : function ( data , escape ) {
310- return '<div class="option">' + escape ( data [ field_label ] ) + '</div>' ;
311+ return '<div class="option ' + ( data [ field_value ] === '' ? 'selectize-dropdown-emptyoptionlabel' : '' ) + ' ">' + escape ( data [ field_label ] ) + '</div>' ;
311312 } ,
312313 'item' : function ( data , escape ) {
313314 return '<div class="item">' + escape ( data [ field_label ] ) + '</div>' ;
You can’t perform that action at this time.
0 commit comments