1

I have a form in jQuery that is submitted remotely:

<%= form_for @order, :remote => true do |f| %>

On the client I am binding to the form submit event (in coffee script):

 $('#new_order').live 'submit', (e) ->

and I want to prevent the rails remote form submit but I can't seem to get it working, I've tried:

 e.preventDefault()
 e.stopPropagation()
 return false

None of these seemed to work. I'm fairly new to Rails so I was wondering if I was missing something about the remote submit handler?

EDIT:

I've found that it works if I use bind instead of live

4

1 に答える 1

1

It seems the issue is that live cannot reliably preventDefault actions bound earlier in the document:

http://api.jquery.com/live/

Calling event.stopPropagation() in the event handler is ineffective in stopping event handlers attached lower in the document; the event has already propagated to document."

Using:

 $('#new_order').on 'submit', (e) ->

does the trick!

于 2012-10-17T17:01:16.320 に答える