I created a rather complex form with 4 nesting levels. Everything works fine except for the deepest link_to_remove. When I click the link, it removes not only all the forms of this nesting level, which it shouldn't, but all records for one level above, too. I have attached an error case which hopefully is understandable.
That's my form:
<%= simple_nested_form_for @order do |f| %>
<%= f.simple_fields_for :order_positions do |g|%>
<%= g.simple_fields_for :component_charts do |h| %>
Test 1
Test 2
<%= h.simple_fields_for :component_chart_positions, wrapper: false do |i| %>
I created a rather complex form with 4 nesting levels. Everything works fine except for the deepest link_to_remove. When I click the link, it removes not only all the forms of this nesting level, which it shouldn't, but all records for one level above, too. I have attached an error case which hopefully is understandable.
That's my form:
<%= h.link_to_remove "Remove component chart" %>
<% end %> <%= g.link_to_add "componen charts add", :component_charts %> <% end %> <% end %>And here is the corresponding JS:
window.NestedFormEvents.prototype.insertFields = function(content, assoc, link) { switch (assoc){ case "component_charts": var $destination = $(link).closest('.fields'); var $new_content = $(content).insertBefore($destination); break; case "component_chart_positions": var $destination = $(link).closest('tr'); var $new_content = $(content).insertAfter($destination); break; } return $new_content; }
I did not add any more code regarding the form. I hope could either help me understand what I'm doing wrong or fix it :)
Thanks!