Im using jquery chained, and Im trying to get the second drop down list to gray out if the first has a blank option selected. Im assuming I need a blank option in the second list for it to lock out, but I'm not sure how to add a blank option. Here is the select option
<%= select_tag :equipment, options_for_select(Equipment.all.collect
{ |e| ["#{e.model} - #{e.serialNum}",e.id,
:class =>"#{e.handReceipt}"]},
html_options = {:id=>'equipment'}) %>
The first drop down list lets you select the hand receipt type, and with jquery chained, the second list only shows records with the appropriate hand receipt attribute.
How would I add a blank option to the above select?
Edit- Here is what I've tried so far -
<%= select_tag :equipment,
options_for_select( [["--",""],
Equipment.all.collect{ |e|
["#{e.model} - #{e.serialNum}",
e.id, :class =>"#{e.handReceipt}"]}],
html_options = {:id=>'equipment'}) %>
This results in an improper display of the list-
<select id="equipment" name="equipment">
<option value="">--</option>
<option value="["M4 - W432156", 10, {:class=>"Arms Room"}]">["PSN-13 - 176985", 1, {:class=>"Commo"}]</option>
</select>
Instead of showing all the records in the table, it just shows a blank option and the second option.
<%= select_tag :equipment,
options_for_select( :include_blank => true,
Equipment.all.collect{ |e|
["#{e.model} - #{e.serialNum}",
e.id, :class =>"#{e.handReceipt}"]},
html_options = {:id=>'equipment'}) %>
Results in the following error -
C:/Users/Sam/Documents/ruby/btrp/app/views/vehicles/edit.html.erb:19: syntax error, unexpected ',', expecting tASSOC
e.id, :class =>"#{e.handReceipt}"]},
Your parameters at options_for_select
is wrong, I think that's the right way:
<%= select_tag :equipment,
options_for_select(Equipment.all.collect { |e|
["#{e.model} - #{e.serialNum}", e.id,
{ :class =>"#{e.handReceipt}" }]}),
:include_blank => true,
:id => 'equipment' %>
Read more at:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With