jquery-ujs icon indicating copy to clipboard operation
jquery-ujs copied to clipboard

late bound forms

Open house9 opened this issue 11 years ago • 6 comments

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?

house9 avatar Jun 19 '13 21:06 house9

+1

eddietejeda avatar Aug 30 '13 21:08 eddietejeda

+1

sfsekaran avatar Oct 25 '13 20:10 sfsekaran

@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.

lucasmazza avatar Oct 31 '13 19:10 lucasmazza

I had this issue once but it was because my form was inside another one with the remote=true attribute

rafaelfranca avatar Oct 31 '13 19:10 rafaelfranca

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.

sfsekaran avatar Oct 31 '13 22:10 sfsekaran

@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.

sfsekaran avatar Nov 12 '13 19:11 sfsekaran