Topic: Adding id parameter to html generated from date_select

I Have the following in my view

<%= date_select 'invoice', 'invoice_date', :order => [:day, :month, :year]  %>

Which in html is turned into
<select name="invoice[invoice_date(3i)]">
...
<option value="5">5</option>
<option value="6" selected="selected">6</option>
...
</select>


<select name="invoice[invoice_date(2i)]">
...
<option value="11">November</option>
<option value="12" selected="selected">December</option>
</select>
#
<select name="invoice[invoice_date(1i)]">
...
<option value="2005">2005</option>
<option value="2006" selected="selected">2006</option>
...
</select>


I would like to set an observe_field on my view however for that I need my generated <select> tags to have an id. So:

1. Is there anyway of generating an id parameter to my <select> tag from date_select?
2. Is there a way to use the name parameter in <select> in order to use observe_field?

Thanx in advance

Fabricio.

Re: Adding id parameter to html generated from date_select

I don't think you can set the id. But, even if you could I don't think it's a good solution because observe_field only observes one field, but you have 3 select menus here. You would need to create 3 observe_field calls and even then it would only pass on the value of the changed menu.

Instead, you may want observe_form. This will pass all the form fields every time one is changed. If you have other fields in the form then you may need to write your own javascript to skip observing the other fields. Unfortunately that's a little out of my experience.

Railscasts - Free Ruby on Rails Screencasts

Re: Adding id parameter to html generated from date_select

Granted, I was planning on writing 3 observe_field's, one for each <select>, :day :month and :year.

I think you are probably right, I have got a couple of other things to observe on the same form anyway, might as well observe the entire form and change things accordingly.

It's very frustrating being a newbie sometimes...

Thanx & Regards,

Fabricio.