jquery chosen, empty String as option

john Smith picture john Smith · Feb 13, 2013 · Viewed 12.9k times · Source

I´m using chosen.js for Dropdowns in a form on a grails-environment. I want the users to be able to select an empty option, but somehow it is ignored. There must be a possibility to do this? Because the workaround to set an option like "select-none" and later in data-bindig make a if condition if select-none value= "" would be unpretty.

to show my problem :

for example this select :

<g:select id="foo" data-placeholder="bar"  class="foo chzn-select" style="width: 245px;" tabindex="4" 
                    from="${['M', ' ', 'F']}" value="foo" name="titel"/>

would return :

enter image description here

Sure this is a nice feature of chosen, but i guess my case is a common case and maybe someone of you already has a solution to override this behaviour

thanks in advance

Answer

weilin8 picture weilin8 · Jun 11, 2013

You can also set *allow_single_deselect* to true. This will have a 'x' that allows user to deselect the option.

$(".chzn-select").chosen({ allow_single_deselect:true });