Skip to content

Commit 12c0e1a

Browse files
dmethvinjitter
authored andcommitted
Fixes #7922. Copy the donor event when simulating a bubbling submit in IE so that we don't accidentally stop propagation on it. Remove a bunch of return statements that could also cancel the event. DRY out the liveFired change from #6359 by moving it to the trigger() function.
1 parent 1ddfdab commit 12c0e1a

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/event.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,7 @@ if ( !jQuery.support.submitBubbles ) {
709709
type = elem.type;
710710

711711
if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
712-
e.liveFired = undefined;
713-
return trigger( "submit", this, arguments );
712+
trigger( "submit", this, arguments );
714713
}
715714
});
716715

@@ -719,8 +718,7 @@ if ( !jQuery.support.submitBubbles ) {
719718
type = elem.type;
720719

721720
if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
722-
e.liveFired = undefined;
723-
return trigger( "submit", this, arguments );
721+
trigger( "submit", this, arguments );
724722
}
725723
});
726724

@@ -783,7 +781,7 @@ if ( !jQuery.support.changeBubbles ) {
783781
if ( data != null || val ) {
784782
e.type = "change";
785783
e.liveFired = undefined;
786-
return jQuery.event.trigger( e, arguments[1], elem );
784+
jQuery.event.trigger( e, arguments[1], elem );
787785
}
788786
};
789787

@@ -797,7 +795,7 @@ if ( !jQuery.support.changeBubbles ) {
797795
var elem = e.target, type = elem.type;
798796

799797
if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
800-
return testChange.call( this, e );
798+
testChange.call( this, e );
801799
}
802800
},
803801

@@ -809,7 +807,7 @@ if ( !jQuery.support.changeBubbles ) {
809807
if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
810808
(e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
811809
type === "select-multiple" ) {
812-
return testChange.call( this, e );
810+
testChange.call( this, e );
813811
}
814812
},
815813

@@ -848,8 +846,18 @@ if ( !jQuery.support.changeBubbles ) {
848846
}
849847

850848
function trigger( type, elem, args ) {
851-
args[0].type = type;
852-
return jQuery.event.handle.apply( elem, args );
849+
// Piggyback on a donor event to simulate a different one.
850+
// Fake originalEvent to avoid donor's stopPropagation, but if the
851+
// simulated event prevents default then we do the same on the donor.
852+
// Don't pass args or remember liveFired; they apply to the donor event.
853+
var event = jQuery.extend( {}, args[ 0 ] );
854+
event.type = type;
855+
event.originalEvent = {};
856+
event.liveFired = undefined;
857+
jQuery.event.handle.call( elem, event );
858+
if ( event.isDefaultPrevented() ) {
859+
args[ 0 ].preventDefault();
860+
}
853861
}
854862

855863
// Create "bubbling" focus and blur events

test/unit/event.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ test("live with change", function(){
14551455
});
14561456

14571457
test("live with submit", function() {
1458+
expect(5);
1459+
14581460
var count1 = 0, count2 = 0;
14591461

14601462
jQuery("#testForm").live("submit", function(ev) {
@@ -1471,7 +1473,16 @@ test("live with submit", function() {
14711473
equals( count1, 1, "Verify form submit." );
14721474
equals( count2, 1, "Verify body submit." );
14731475

1476+
jQuery("#testForm input[name=sub1]").live("click", function(ev) {
1477+
ok( true, "cancelling submit still calls click handler" );
1478+
});
1479+
1480+
jQuery("#testForm input[name=sub1]")[0].click();
1481+
equals( count1, 2, "Verify form submit." );
1482+
equals( count2, 2, "Verify body submit." );
1483+
14741484
jQuery("#testForm").die("submit");
1485+
jQuery("#testForm input[name=sub1]").die("click");
14751486
jQuery("body").die("submit");
14761487
});
14771488

0 commit comments

Comments
 (0)