#7061 closed bug (fixed)
Delegated submit handler can interfere with default action of click event on IE
Reported by: | Tgr | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | event | Version: | 1.4.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Submit delegation being simulated with click delegation in IE can have unexpected results. Consider the following code:
$('html').delegate('form', 'submit', function() { $(this).find(':submit').attr('disabled', true); });
which is a common way to prevent accidental double postings; delegation is used to make sure this will execute after validation etc. submit handlers.
This will work fine in most browsers, but submit does not bubble in IE, and jQuery simulates it via the click event. When you set the submit button to disabled inside a click handler, the form will not submit, because the default action for clicking a disabled button is to do nothing.
I'm not sure if this counts as a bug, or just a perk of the cross-browserization of event delegation, but maybe you could use click handlers to detect submit delegation, and when detected, add a new submit handler to the form (and then remove it as needed) so that the event handler is actually run as a submit handler, not a click handler?
On a partially related note, please add jQuery.support.submitBubbles/changeBubbles to the http://api.jquery.com/jQuery.support/ doc page.
Change History (13)
comment:1 Changed 12 years ago by
Priority: | → undecided |
---|
comment:2 Changed 12 years ago by
Keywords: | needsreview added |
---|---|
Milestone: | 1.4.3 |
Priority: | undecided → low |
Review as per comment:1 by dmethvin.
comment:4 Changed 12 years ago by
I vote for fixing this. If you are attempting to simulate the submit event in IE, then you shouldn't introduce an unexpected behavior by your chosen solution (a click). If it is supposed to simulate the submit event, then it should submit even when the button is disabled. Otherwise, the simulation seems half-baked.
comment:6 Changed 12 years ago by
This issue effects disabling the submit button functionality for IE7 and IE8 under jQuery 1.4.4 still. Specifically causing issues with the Rails UJS driver https://github.com/rails/jquery-ujs/issues/#issue/30
comment:7 Changed 12 years ago by
Milestone: | → 1.next |
---|
comment:8 Changed 12 years ago by
Keywords: | needsreview removed |
---|---|
Status: | new → open |
comment:13 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Fix #7061. Lazy-attach to the genuine submit event for delegation.
Avoids the problems that arise when we try to trigger submit behavior at clicky-time.
Changeset: a4cdbf09ee97471ec041d83ceb8f3feb9825b2a1
I've updated the docs to expose submitBubbles and changeBubbles. The remaining open issue is to determine whether this quirk of the delegate/live submit handler should be fixed or simply documented.