How do I set the id attribute in my drop down boxes?
Here is the part of my form in question:
<%= f.fields_for :items do |builder| %>
<%= builder.label :description %><br />
<%= builder.text_field :description %><br />
<%= builder.label :material %><br />
<%= builder.select :material, @letters.map { |l| [l.material, l.material] }, :id => "material_field" %><br />
<%= builder.label :height %><br />
<%= builder.select :height, @letters.map { |l| [l.height, l.height] }, :id => "height_field" %><br />
<%= builder.label :thickness %><br />
<%= builder.select :thickness, @letters.map { |l| [l.thickness, l.thickness] }, :id => "thickness_field" %><br />
<%= builder.label :quantity %><br />
<%= builder.text_field :quantity, :id => "quantity_field" %>
<%= builder.link_to_remove "Remove this item" %>
<% end %>
The :id => "quantity_field" method works for text fields, but not for the select fields. Viewing the HTML source I am getting an id of "estimate_items_attributes_0_material" for the material text box.
This is a strange inconsistency. Any help will be greatly appreciated.
There is a parameter between the possible choices and the html options. So you have to do this :
<%= builder.select :thickness, @letters.map { |l| [l.thickness, l.thickness] }, {}, :id => "thickness_field" %>
You can find the doc here : http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-select
And this one can also be helpful : http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
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