ryanb / nested_form

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

hide elements from DOM if _destroy="true" after validation errors #301

Closed kuldeepaggarwal closed 10 years ago

kuldeepaggarwal commented 10 years ago

When we remove the nested element by clicking on Remove link then we hide the elements using JS, but then if we submit the form and error occurs, form again renders and the last removed(hidden) elements have shown on the DOM with _destroy="true", and now if submit the form correctly, it passes the params with _destroy="true" => which would destroy the nested elements, so I think we should not display the last removed(hidden) elements after errors occur on the server.

lest commented 10 years ago

Thanks for the pull request but it's made intentionally. Here is a quote from README:

In order to choose how to handle, after validation errors, fields that are marked for destruction, the marked_for_destruction class is added on the div if the object is marked for destruction.
dahbearz commented 9 years ago

I think this problem still exists. If I generate several empty elements and then proceed to delete all of them and submit the form for validations. If validations fail, all the fields that I deleted will reappear and there is no way of removing them without filling all elements with valid data.