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 <option> 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: <p> <b> <label class="input_box_label" for="select_is_invoicable" id="label_is_invoicable"> Issue Invoices in this Currency </label> </b> <br/> <select id="select_is_invoicable" name="currency[is_invoicable]" size="1" title="May invoices be issued in this currency?"> <option value="true" id="invoicable_true>Yes</option> <option value="false" selected="selected" id="invoicable_false">No</option> </select> </p> 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? -- Posted via http://www.ruby-forum.com/.
2009/6/19 James Byrne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > 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 > <option> 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: > > <p> > <b> > <label class="input_box_label" > for="select_is_invoicable" > id="label_is_invoicable"> > Issue Invoices in this Currency > </label> > </b> > <br/> > <select id="select_is_invoicable" > name="currency[is_invoicable]" > size="1" > title="May invoices be issued in this currency?"> > > <option value="true" > id="invoicable_true>Yes</option> > <option value="false" selected="selected" > id="invoicable_false">No</option> > </select> > </p> > > 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 Law wrote:> 2009/6/19 James Byrne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> >> </label> >> id="invoicable_false">No</option> >> </select> >> </p> >> >> 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. > > ColinI 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? -- Posted via http://www.ruby-forum.com/.
2009/6/19 James Byrne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> >... > > 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 %><br /> <%= f.select :location_id, Location.get_names_and_ids %> provides <label for="note_location_id">Location</label><br /> <select id="note_location_id" name="note[location_id]"><option value="31">Brechfa Blaen-hauliw 1 SN535364</option> <option value="32">Brechfa Blaen-hauliw 2 SN531362</option>... Which is not what you are looking for at all :( On second thoughts I think you may have to do it yourself. Sorry Colin