ryanb / nested_form

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

nested_form shows extra fields after error messages #368

Open Mingus85 opened 8 years ago

Mingus85 commented 8 years ago

I'm using simple_nested_form_for to build a form with nested fields. When I press submit, I get the correct params hash, and validation seems to work. When after some validations do not pass I re-render the form via the create action, however, the nested fields are displayed incorrectly. The same nested fields are shown multiple times.

Also, in my simple_fields_for the FormBuilder index is shown as a semi random number such as 1454793731550, whereas after re-rendering it is displayed in normal increments 0-n.

Ashviniv commented 7 years ago

@Mingus85 Can you please share your code?. especially, the create action of the controller. It is just to know what you are exactly trying to do. And the last part is because , Using the nested form, we add fields dynamically, so for the first time when form is rendered, we donot initialize any objects of the child class. The FormBuilder object is yielded when usingform_for or fields_for. and When these values are submitted to server, we initialize objects so next time when it is re-render it is displayed with its object ids.