jquery - Rails[Cocoon]: add link persists despite removed field? -


i'm on rails 4 using latest cocoon gem. working perfectly; issue when remove nested fields, add link persists. in readme, link add in _form while link remove in _[model]_fields. i'm using simpleform:

_form.html.erb

<%= simple_form_for(@group) |f| %>   <%= f.input :name, :label_html => { class: "col-md-2" }, :input_html => { class: "col-md-10" } %>   <div id="group_names">     <%= f.simple_fields_for :group_names |subgroup| %>       <%= render 'group_name_fields', :f => subgroup %>       <div class="links">         <%= link_to_add_association 'add', f, :group_names %>       </div>     <% end %>   </div> <% end %> 

_group_names_fields.html.erb

<div class="nested-fields">   <%= f.input :subgroup, :label_html => { class: "col-md-2" }, :input_html => { class: "col-md-10" }, :required => false %>   <%= link_to_remove_association "remove", f %> </div> 

what did miss? note: not missing submit button, submission works deletion. it's add link not go away. simple sure have done wrong, cannot seem spot it. otherwise, thinking wrapping add link in if statement i'm not sure condition be.

thanks!

answer: <%= link_to_add_association 'add', f, :group_names %> should outside <%= f.simple_fields_for :group_names |subgroup| %> loop. solved new current issue, bonus!

this code listed in in cocoon readme in haml:

= simple_form_for @project |f|   = f.input :name   = f.input :description   %h3 tasks   #tasks     = f.simple_fields_for :tasks |task|       = render 'task_fields', :f => task     .links       = link_to_add_association 'add task', f, :tasks   = f.submit 

i don't know haml, don't know if haml thing, .links not in fact in f.simple_fields_for loop after all.


Comments