Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery chosen, empty String as option

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

like image 875
john Smith Avatar asked Feb 13 '13 10:02

john Smith


3 Answers

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 });
like image 173
weilin8 Avatar answered Sep 19 '22 20:09

weilin8


after some research i found this thread

https://github.com/harvesthq/chosen/issues/93

and my solution was prepending an option via JS before initialisation of chosen

$("#id").prepend("<option value='' >&nbsp;</option>");

So this one is Resolved, thanks to &nbsp; and everyone who had a look at this

like image 31
john Smith Avatar answered Sep 19 '22 20:09

john Smith


<g:select name="foo" from="${foos}" noSelection="[' ':' ']"  />  
like image 3
moskiteau Avatar answered Sep 21 '22 20:09

moskiteau