i have simple_form remote: true. i'm adding nested fields (people example) cocoon.
<%= simple_form_for @incorporation, html: {id:"incorporationform"}, remote: true, update: { success: "response", failure: "error"} |f| %> <%= f.simple_fields_for :company |company| %> <div id="people" class="form_section"> <div class="form-right"> <div id="dynamic-person" class="dynamic-entity level1 person entityattributes"> <%= company.simple_fields_for :people |person|%> <%= render 'person_fields', f: person %> <% end %> <div><%= link_to_add_association 'add person', company, :people, class: "btn btn-default add-button" %></div> </div> </div> </div> this works except under particular circumstance. if i'm editing form that's been saved database few people on it, cannot perform following sequence of activities:
- remove person
link_to_remove_association - save changes via ajax (remember,
remote: true) - make other changes
- save via ajax again
everything works until try perform second save, @ point i'm confronted following error:
19:19:38 web.1 | activerecord::recordnotfound (couldn't find person id=33 company id=1): the person id=33 refers person removed in step 1. when check people table, in database. person 33 indeed gone (indicating save in step 2 good). interpretation of what's going on after saving removal, remote form forgets person 33 gone , goes looking him on next save.
to absolutely clear, there no issue if remote: false or if refresh page between steps 2 & 3.
anyone have guess @ solution this? many in advance gives shot.
edit
upon further research, appears cocoon not built handle ajax submissions. it seems can gotten around replacing elements in dom asynchronously. comment provides summary of process used. i'm guessing did <%= escape_javascript(render(:partial => _person_fields.html.erb)) %> i'm unfamiliar asynchronous rendering of partials. imagine have remove current partial dom , load new version of it. right idea? if so, what's best way remove old partial, straight jquery?
Comments
Post a Comment