Skip to main content

Bug Tracker

Side navigation

#7061 closed bug (fixed)

Opened September 22, 2010 09:56AM UTC

Closed September 22, 2011 01:39AM UTC

Last modified March 10, 2012 04:44AM UTC

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.

Attachments (0)
Change History (13)

Changed October 03, 2010 07:49PM UTC by dmethvin comment:1

priority: → undecided

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.

Changed October 15, 2010 12:00AM UTC by snover comment:2

keywords: → needsreview
milestone: 1.4.3
priority: undecidedlow

Review as per comment:1 by dmethvin.

Changed November 02, 2010 03:09AM UTC by dmethvin comment:3

Changed November 05, 2010 06:23PM UTC by anonymous comment:4

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.

Changed November 21, 2010 10:07PM UTC by snover comment:5

There’s a 3rd party pull request open for this bug.

Changed January 12, 2011 09:15PM UTC by cracell comment:6

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

Changed April 17, 2011 08:16PM UTC by john comment:7

milestone: → 1.next

Changed July 12, 2011 09:34PM UTC by dmethvin comment:8

keywords: needsreview
status: newopen

Changed August 16, 2011 07:08PM UTC by ljharb comment:9

Any progress on this?

Changed September 08, 2011 06:21PM UTC by dmethvin comment:10

Related to #6262, and equally hard to fix.

Changed September 08, 2011 07:24PM UTC by dmethvin comment:11

#6262 is a duplicate of this ticket.

Changed September 08, 2011 07:25PM UTC by dmethvin comment:12

#8748 is a duplicate of this ticket.

Changed September 22, 2011 01:39AM UTC by Dave Methvin comment:13

resolution: → fixed
status: openclosed

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