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

1
  • Maybe you should bind your custom actions to the form button click event, instead of the submit one. Just a guess though. Commented Oct 17, 2012 at 16:47

1 Answer 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!

Sign up to request clarification or add additional context in comments.

1 Comment

Ran into this problem on some older legacy code and switching to on worked like a charm :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.