Bug Tracker

Modify

Ticket #9704 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 3 years ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfiled to event

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

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

Last edited 3 years ago by rwaldron (previous) (diff)

comment:2 Changed 3 years ago by mcm

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.

comment:3 Changed 3 years ago by dmethvin

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.

comment:4 Changed 3 years ago by mcm

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.

comment:5 Changed 2 years ago by Chealer

See also #3115. Perhaps there's a documentation problem here.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.