Skip to main content

Bug Tracker

Side navigation

#9704 closed enhancement (wontfix)

Opened June 30, 2011 12:10AM UTC

Closed June 30, 2011 12:18AM UTC

Last modified January 21, 2012 08:19PM UTC

trigger jquery submit handlers when vanilla javascript calls form.submit()

Reported by: mcm Owned by:
Priority: low Milestone: 1.next
Component: event Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:
Description

In asp.net linkbuttons aren't triggering my jquery form submit handlers. The problem appears to be because linkbuttons are rendered as an A tag and javascript is used to submit the form. This could apply to other frameworks too.

I propose adding a hook to the form's submit method to trigger the jquery submit handlers:

$("form").each(function() {

var oldSubmit = this.submit;

this.submit = function() {

$(this).triggerHandler("submit");

oldSubmit.apply(this, arguments);

}

});

N.B. Sample code hasn't hooked up the approaches to cancelling the form submission.

Attachments (0)
Change History (5)

Changed June 30, 2011 12:18AM UTC by rwaldron comment:1

_comment0: Links won't trigger a submit unless you tell them too \ \ http://jsfiddle.net/rwaldron/BSatT/1309393153167938
component: unfiledevent
priority: undecidedlow
resolution: → wontfix
status: newclosed

Links won't trigger a submit unless you tell them to

http://jsfiddle.net/rwaldron/BSatT/

Changed July 01, 2011 02:38AM UTC by mcm comment:2

I think you've misinterpreted my request (I was not clear at all, the bug title was the request and the description was the reason why I want it plus a workaround I'm currently using). Basically I want to be able call submit using standard javascript (what I meant by vanilla javascript in the title):


document.getElementById("form").submit();

And for this to trigger the submit event handler I've bound using jquery:

$("#form").submit(function() { ... });

This works fine with with other events like click. Here is the demonstration, sorry for not providing this before:

http://jsfiddle.net/abRu4/

As you can see when run, only the hyperlink alert pops up not the form.

Changed July 03, 2011 12:47AM UTC by dmethvin comment:3

That would be a significant and breaking change. Note that even without jQuery in play, the DOM form.submit() method does not call the onsubmit handler for the form.

See #4930 and #5722.

I am not sure about the architecture of ASP.NET linkbuttons but perhaps you could patch its submit method for the form so that it runs your handler and then does the submit.

Changed July 05, 2011 07:20AM UTC by mcm comment:4

Cool thanks for the prompt response and links to the duplicate bug report. Sorry for not finding it before filing this one.

Indeed I hadn't realised this was the case for calling form.submit() as well. I agree with warp it's something that would be helpful to mention in the documentation, since it wasn't expected and one of the benefits of jquery is normalising behaviour.

Changed January 21, 2012 08:19PM UTC by Chealer comment:5

See also #3115.

Perhaps there's a documentation problem here.