Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name the blank value in select?

I use simple_form in my app.

How do i give the blank value in my selects a different text than "" ?

I just find an option to include blank or not.

like image 573
Ben Avatar asked Apr 05 '12 21:04

Ben


2 Answers

It depends on how you are constructing your options for select. If you're doing it like the code below, just pass a string into the :include blank.

select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'Some text here'}) 

If you're setting the options with a options_for_select(), then you can do something like the following:

options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) 

With the value="" being the second value in the array and the name that shows up in the dropdown being first. So in your case, you could change the second answer to look like this:

options_for_select([["Some text here", ""], ["Dollar", "$"], ["Kroner", "DKK"]]) 
like image 128
Josh Moore Avatar answered Sep 19 '22 23:09

Josh Moore


Instead of

:include_blank => true 

Try

:include_blank => "your text here" 

if this is what you are looking.

like image 35
Demetris Constantinou Avatar answered Sep 22 '22 23:09

Demetris Constantinou