ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

The label does not match the ID of the input field: #314

Closed jankeesvw closed 10 years ago

jankeesvw commented 10 years ago

This is an example of the outputted HTML, you can see the the for attribute for the <label> does not match the id of the <input>. These should be the same so the user can click a label to enter a textfield. This also breaks some feature testing which relies on the same link.

<div class="field">
  <label for="ride_start_point">Start punt</label>
  <input id="ride_legs_attributes_1394709145279_start_point" name="ride[legs_attributes][1394709145279][start_point]" type="text">
</div>
jankeesvw commented 10 years ago

A few minutes ago I cloned this project to fix this issue, after trying to build a spec to reproduce it I found out that there was an error in my implementation. I was using the original form object and not the forms_for form:

Simplified version that shows my mistake:

= nested_form_for @ride do |f|
  = f.fields_for :legs do |leg_form|
    .field
      = f.label :start_point
      = leg_form.text_field :start_point