Side navigation
#4678 closed bug (invalid)
Opened May 20, 2009 07:26PM UTC
Closed May 21, 2009 12:45AM UTC
Last modified March 15, 2012 06:23PM UTC
Form Submit handler not working
Reported by: | shwoodard | Owned by: | brandon |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | event | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I created an event handler for a form, 'submit'. I then called submit() on that form and the event handler hit briefly and then submited the form despite the fact that the first line of my event handler was evt.preventDefault(). I found a fix but it was rather hackish.
More details: I had two files both loaded on the same page.
File 1:
$(document).ready(function() {
$('.myForms').live('submit', function (evt) {
evt.preventDefault();
//do more stuff
}
});
File 2:
$(document).ready(function () {
$('.myLink').live('click', function (evt) {
$(this).closest('form').submit();
});
});
The form in file 2 was one of the forms for which the sumbit handler in file 1 was registered. However the prevent default did not work.
I had to apply the following hack:
file 2:
$(document).ready(function () {
$('.myLink').live('click', function (evt) {
$(this).closest('form').bind('submit, function(evt) { evt.preventDefault(); }.submit();
});
});
In the case of my hack/fix, the event handler in file 2 was hit to prevent default on the submit event and then the event handler for submit in file 1 was hit and the form serialization and ajax that is performed by that function could go down.
Why was the one submit handler in file 1 not adequate?
Attachments (0)
Change History (1)
Changed May 21, 2009 12:45AM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
The documentation is clear that the
event is *not* supported by the method:http://docs.jquery.com/Events/live#typefn
Many form events such as
are not bubbled in IE, btw, so it's trickier to support than you might think.