Multiple remote_form_for on the same page causes duplicate ids

Posted by Ben Scheirman on Stack Overflow See other posts from Stack Overflow or by Ben Scheirman
Published on 2010-03-11T14:29:09Z Indexed on 2010/03/11 19:54 UTC
Read the original article Hit count: 291

Filed under:

I've got a rails app that displays a list of items called modules. I'm iterating over these, rendering a partial for each one that includes a remote_form_for call.

This all works, but fails HTML validation because my form text fields all have the same id.

Is there a :prefix option on the form (or something else) I can use to get around this?

Update:
(some code)

    //_module_form.html.erb
    <% remote_form_for app_module do |f| %>
         <%= f.label :name %>
         <%= f.text_field :name %>
         <%= submit_tag 'Save' %>
    <%end %>

    //parent page
    <% @thing.modules.each do |app_module| %>
       <%= render :partial => "module_form", :locals => { :app_module => app_module } %>
    <% end %>

So if I have more than 1 item in the collection, I render the identical form on the same page, and the form id and textbox id are duplicated.

I can customize the form id pretty easily, but what about the text_box, since the controller is looking for specific named controls?

© Stack Overflow or respective owner

Related posts about ruby-on-rails