OK, here's an example of what I'm trying to do.

_form.html.erb

<%= form.error_messages %>
<p>
  <%= form.label :title %><br />
  <%= form.text_field :title %>
</p>
<p>
  <%= form.label :due_date %><br />
  <%= form.datetime_select :due_date %>
</p>
<div id="tasks">
  <h3>Tasks</h3>
  <% form.fields_for :tasks do |task_form| -%>
    <%= render :partial => 'task', :locals => { :form => task_form }
%>
  <% end -%>
</div>
<%= add_task_link(form) %>
<p>
  <%= form.submit 'Save' %>
</p>

And here's the partial that gets called above (_task.html.erb)

<div class="task">
  <p>
    <%= form.label :name %>
    <%= form.text_field :name, :size => 15 %>
    <%= remove_task_link( form ) %>
  </p>
  <%= observe_field :project_tasks_attributes_0_name, :function =>
'alert("field changed")' %>
</div>

This doesn't work because I need to change the observe_field name
(:project_tasks_attributes_0_name) for each task.  If I had 3 tasks,
the
then the observe_field names would be:
:project_tasks_attributes_0_name
:project_tasks_attributes_1_name
:project_tasks_attributes_2_name

I was wondering if there is a way to access the index of the task form
loop to generate field names like the above.

Thanks,
Jay

On Aug 17, 9:35 pm, bill walton <[email protected]> wrote:
> Hi Jay,
>
> On Mon, 2009-08-17 at 14:24 -0700, Jay wrote:
> > I'm trying to observe a field that get generated inside a fields_for
> > loop (I'm trying to create the form dynamically depending on a
> > selection value).  Is there a way to access the index in the field_for
> > loop?
>
> What do you mean by 'index'?  The observe_field method takes a DOM id.
> If you're having trouble, post the view and the page source that
> results. It's very difficult to help with such sparse information.
>
> Best regards,
> Bill
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to