jquery - remote: true doen't work inside a modal -
so got form remote: true , work excepted when i'm on form page.
but form supposed in modal. when try form in modal doesn't work.
i got 2 cases:
form_for(@report, remote: true, method: 'post') that throw error because it's looking html template :
reportscontroller#create missing template request format , variant. request.formats: ["text/html"] request.variant: [] and
form_for(@report, format: "js", remote: true, method: 'post') just follow link js view.
i'm pretty sure bug due fact load form asynchronously with:
$.ajax({ url: "/form/url" }) but can't figure out do.
as complement information, use vex lib modal displaying.
i faced same problem , still trying figure why remote: true won't work inside modal, able same behavior skipping remote: true , adding ajax call manually.
so, can around this; check (reduced) code used in _form.html.erb partial rendered inside modal1:
<div> <%= form_tag company_users_url, id: "company-users-form" |f| %> select file: <%= file_field_tag :file %> <%= submit_tag "send" %> <% end %> <div> <script> $("#company-users-form").submit(function(event){ event.preventdefault(); var formdata = new formdata($(this)[0]); $.ajax({ url: '<%= company_users_url %>', type: 'post', data: formdata, async: false, cache: false, contenttype: false, enctype: 'multipart/form-data', processdata: false }); return false; }); </script> with setup, first use regular remote: true call on form opens modal renders above partial. then, within partial if send form, call sent again js, js.erb view rendered correctly; in case line new modal content:
$('#company-users-modal').html("<%= j(@new_content) %>"); 1 notice use of formdata simplicity.
Comments
Post a Comment