Commit 92a92be1 authored by Dave Methvin's avatar Dave Methvin

Fix #11049. Let bubbling submit be cancellable in oldIE.

parent 619f0d90
...@@ -391,6 +391,7 @@ jQuery.event = { ...@@ -391,6 +391,7 @@ jQuery.event = {
delegateCount = handlers.delegateCount, delegateCount = handlers.delegateCount,
args = [].slice.call( arguments, 0 ), args = [].slice.call( arguments, 0 ),
run_all = !event.exclusive && !event.namespace, run_all = !event.exclusive && !event.namespace,
special = jQuery.event.special[ event.type ] || {},
handlerQueue = [], handlerQueue = [],
i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related; i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related;
...@@ -398,6 +399,11 @@ jQuery.event = { ...@@ -398,6 +399,11 @@ jQuery.event = {
args[0] = event; args[0] = event;
event.delegateTarget = this; event.delegateTarget = this;
// Call the preDispatch hook for the mapped type, and let it bail if desired
if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
return;
}
// Determine handlers that should run if there are delegated events // Determine handlers that should run if there are delegated events
// Avoid non-left-click bubbling in Firefox (#3861) // Avoid non-left-click bubbling in Firefox (#3861)
if ( delegateCount && !(event.button && event.type === "click") ) { if ( delegateCount && !(event.button && event.type === "click") ) {
...@@ -467,6 +473,11 @@ jQuery.event = { ...@@ -467,6 +473,11 @@ jQuery.event = {
} }
} }
// Call the postDispatch hook for the mapped type
if ( special.postDispatch ) {
special.postDispatch.call( this, event );
}
return event.result; return event.result;
}, },
...@@ -758,10 +769,7 @@ if ( !jQuery.support.submitBubbles ) { ...@@ -758,10 +769,7 @@ if ( !jQuery.support.submitBubbles ) {
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined; form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
if ( form && !form._submit_attached ) { if ( form && !form._submit_attached ) {
jQuery.event.add( form, "submit._submit", function( event ) { jQuery.event.add( form, "submit._submit", function( event ) {
// If form was submitted by the user, bubble the event up the tree event._submit_bubble = true;
if ( this.parentNode && !event.isTrigger ) {
jQuery.event.simulate( "submit", this.parentNode, event, true );
}
}); });
form._submit_attached = true; form._submit_attached = true;
} }
...@@ -769,6 +777,16 @@ if ( !jQuery.support.submitBubbles ) { ...@@ -769,6 +777,16 @@ if ( !jQuery.support.submitBubbles ) {
// return undefined since we don't need an event listener // return undefined since we don't need an event listener
}, },
postDispatch: function( event ) {
// If form was submitted by the user, bubble the event up the tree
if ( event._submit_bubble ) {
delete event._submit_bubble;
if ( this.parentNode && !event.isTrigger ) {
jQuery.event.simulate( "submit", this.parentNode, event, true );
}
}
},
teardown: function() { teardown: function() {
// Only need this for delegated form submit events // Only need this for delegated form submit events
if ( jQuery.nodeName( this, "form" ) ) { if ( jQuery.nodeName( this, "form" ) ) {
......
...@@ -1216,7 +1216,7 @@ test("Delegated events in SVG (#10791)", function() { ...@@ -1216,7 +1216,7 @@ test("Delegated events in SVG (#10791)", function() {
test("Delegated events in forms (#10844; #11145; #8165)", function() { test("Delegated events in forms (#10844; #11145; #8165)", function() {
expect(3); expect(3);
// Aliases names like "id" cause havoc // Alias names like "id" cause havoc
var form = jQuery( var form = jQuery(
'<form id="myform">'+ '<form id="myform">'+
'<input type="text" name="id" value="secret agent man" />'+ '<input type="text" name="id" value="secret agent man" />'+
...@@ -1259,6 +1259,44 @@ test("Delegated events in forms (#10844; #11145; #8165)", function() { ...@@ -1259,6 +1259,44 @@ test("Delegated events in forms (#10844; #11145; #8165)", function() {
form.remove(); form.remove();
}); });
test("Submit event can be stopped (#11049)", function() {
expect(1);
// Since we manually bubble in IE, make sure inner handlers get a chance to cancel
var form = jQuery(
'<form id="myform">'+
'<input type="text" name="sue" value="bawls" />'+
'<input type="submit" />'+
'</form>'
)
.appendTo("body");
jQuery( "body" )
.on( "submit", function() {
ok( true, "submit bubbled on first handler" );
return false;
})
.find( "#myform input[type=submit]" )
.each( function(){ this.click(); } )
.end()
.on( "submit", function() {
ok( false, "submit bubbled on second handler" );
return false;
})
.find( "#myform input[type=submit]" )
.each( function(){
jQuery( this.form ).on( "submit", function( e ) {
e.preventDefault();
e.stopPropagation();
});
this.click();
})
.end()
.off( "submit" );
form.remove();
});
test("jQuery.Event( type, props )", function() { test("jQuery.Event( type, props )", function() {
expect(5); expect(5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment