Binding custom actions for AJAX

Oct 12, 2011 at 9:41 PM

Hi there.

See original topic on old forum for history.

Based on your suggestion of binding my custom action buttons like this:

$(function () { $(".QButtons form.Action").live("submit", nakedObjects.updatePageFromAction); });

I did this:

$("div.xButtons form.Action").live("submit", nakedObjects.updatePageFromAction);

It correctly binds the custom action buttons and clicking on them correctly triggers an AJAX call.

However, it causes my top menu actions to bounce back to the index page after bringing up the correct view as per the action, and then it goes back to the correct view after flashing the index page. When I comment out that line then the top menu actions behave correctly. And I have confirmed that the selector does not match the top level menu buttons. So I am confused as to why having that line on my script load should cause this behavior.

Any thoughts?

Another thing, surely you are wanting to bind the "submit" event on the actual button elements with the .live() call, so why do you end the selector on "... form.Action" instead of "... form.Action button"? I see you do the same in your own js file, and it obviously works, I just don't understand why.


Oct 12, 2011 at 10:09 PM

OK, I forgot to mention that the strange behavior was only occurring on IE. But anyway, I found the reason. I was doing the bind directly in the top of my js, instead of in a jQuery ready function. It now works correctly.

Still have the selector question though. :)

Oct 13, 2011 at 7:18 AM
Edited Oct 13, 2011 at 7:22 AM

Because 'submit' events can only be bound to forms.

Oct 13, 2011 at 7:31 AM
Ok, that makes a lot of sense. :)