I am writing a test suite which depends upon begin able to use the html
id attribute so that the tests are display language independent. The
tag supports this attribute. In fact it supports, among
others, the CLASS, DISABLED, ID, LABEL, SELECTED, STYLE, TITLE, and
VALUE attributes. What I cannot seem to discern from the select API is
how to set the ID attribute on a specific option.
The API refers to options_for_select but I cannot see from that how to
accomplish what I desire.
The specific case that I am dealing with involves a select box for yes
or no. The model attribute is a boolean. I desire to have this sort of
output from the form builder:
Issue Invoices in this Currency
<option value="true"
id="invoicable_true>Yes</option>
<option value="false" selected="selected"
id="invoicable_false">No</option>
</select>
I can get everything except the id=“invoicable_true” and
id=“invoicable_false” against their specific options.
Is this possible with the existing select form helper or needs be I roll
my own?
2009/6/19 James B. [email protected]:
 Â
         id=“invoicable_false”>No
 Â
I can get everything except the id=“invoicable_true” and
id=“invoicable_false” against their specific options.
Is this possible with the existing select form helper or needs be I roll
my own?
Assuming I understand the issue correctly then to achieve this I use
f.select inside a form_for. This takes an array of values and ids for
the options. I must admit though that I use integer values for the id
values so whether this will work in the way you require I am not sure.
Colin
Colin L. wrote:
2009/6/19 James B. [email protected]:
 Â
         id=“invoicable_false”>No
 Â
I can get everything except the id=“invoicable_true” and
id=“invoicable_false” against their specific options.
Is this possible with the existing select form helper or needs be I roll
my own?
Assuming I understand the issue correctly then to achieve this I use
f.select inside a form_for. This takes an array of values and ids for
the options. I must admit though that I use integer values for the id
values so whether this will work in the way you require I am not sure.
Colin
I am already using the select helper inside a form_for construct. Could
you show me a small example of what you do and what the page source
generated looks like?
2009/6/19 James B. [email protected]:
…
I am already using the select helper inside a form_for construct. Â Could
you show me a small example of what you do and what the page source
generated looks like?
<% form_for(@note) do |f| %>
…
<%= f.label :location_id %>
<%= f.select :location_id, Location.get_names_and_ids %>
provides
Location
Brechfa Blaen-hauliw 1 SN535364
Brechfa Blaen-hauliw 2 SN531362...
Which is not what you are looking for at all 
On second thoughts I think you may have to do it yourself.
Sorry
Colin