1

According to the docs for Form Helper's form_for:

The form_for method automatically includes the model id as a hidden field in the form. This is used to maintain the correlation between the form data and its associated model. Some ORM systems do not use IDs on nested models so in this case you want to be able to disable the hidden id.

This makes sense and is important, but if you have two form_for calls on the same page, it generates two hidden fields with the same markup and the same id. In my case, it generates this twice on the same page:

<input id="clinic_patient_signup_clinic_patient_link_person_attributes_patient_information_attributes_id" name="clinic_patient_signup[clinic_patient_link][person_attributes][patient_information_attributes][id]" type="hidden" value="32" /></div>

Is there a way to overwrite the id attribute of that input? If I remember correctly, it's just the name attribute that is important, and the value can stay the same. Our site has to be WCAG 2.0 accessibility compliant, and it won't allow two tags on the same page with the same id. (That's also not valid HTML.)

nickcoxdotme
  • 6,567
  • 9
  • 46
  • 72
  • this question had been ansowered in [here] [1]: http://stackoverflow.com/questions/8682076/change-html-form-id-generated-by-form-for-rails-3-1 – Raymond Liu Apr 30 '14 at 02:02
  • No, that's to change the id of the form. This is the id of the hidden field that `fields_for` adds. – nickcoxdotme Apr 30 '14 at 18:37

1 Answers1

0

Use the form_for :namespace option.

See https://stackoverflow.com/a/26415985/2511083 for a complete answer.

Community
  • 1
  • 1
Subtletree
  • 3,169
  • 2
  • 18
  • 25