jquery-ujs
jquery-ujs copied to clipboard
late bound forms
I have a rails form with remote => true
(renders as data-remote="true"), normally rails jquery-ujs would modify this form to submit using ajax request - however my form is getting appended to the DOM based on user action and jquery-ujs appears to fire during document loading only - leaving my form as a non-ajax form
any ideas how I can get jquery-ujs to activate my late bound form?
looking through the source code:
- I can manually can fire it off from firebug console -
$.rails.handleRemote($('#my-late-bound-form'));
but this doesn't work from a form submit event, only directly in the console. - Also tried -
$('#my-late-bound-form').bind('submit.rails');
- after appending to the DOM, but no luck, came up with CSRF errors
worst case I can just manually code up my ajax calls for the late bound forms, that code is rather trivial, just not as simple as remote=>true
wondering if I am missing something and this is actually easy to do?
+1
+1
@house9 @eddietejeda @sfsekaran is this still an issue for anyone? Currently jquery-ujs binds all events to the document element to support late bound elements through event delegation, so this should work out of the box for any HTML appended to the document after page load.
I had this issue once but it was because my form was inside another one with the remote=true
attribute
Context: I used the master version of jquery-ujs as of 6 days ago, with jQuery 1.10.1.
I'll be checking this again soon, and I'll report back.
@lucasmazza Nevermind. For some reason, it's working again and honestly I'm not sure what I changed to fix it. I'll be back if something like this crops up again.