Skip to content
Permalink
Browse files

Fix #11649. Preserve oldIE submit flag when cloning, closes gh-772.

  • Loading branch information...
MoonScript authored and dmethvin committed May 18, 2012
1 parent 6bf3f20 commit e93f2a89e277d3fffbc15b4ef82ebc3ac6a840f5
Showing with 37 additions and 3 deletions.
  1. +2 −2 src/event.js
  2. +0 −1 src/manipulation.js
  3. +35 −0 test/unit/event.js
@@ -772,11 +772,11 @@ if ( !jQuery.support.submitBubbles ) {
// Node name check avoids a VML-related crash in IE (#9807)
var elem = e.target,
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
if ( form && !form._submit_attached ) {
if ( form && !jQuery._data( form, "_submit_attached" ) ) {
jQuery.event.add( form, "submit._submit", function( event ) {
event._submit_bubble = true;
});
form._submit_attached = true;
jQuery._data( form, "_submit_attached", true );
}
});
// return undefined since we don't need an event listener
@@ -467,7 +467,6 @@ function cloneFixAttributes( src, dest ) {

// Clear flags for bubbling special change/submit events, they must
// be reattached when the newly cloned events are first activated
dest.removeAttribute( "_submit_attached" );
dest.removeAttribute( "_change_attached" );
}

@@ -1062,6 +1062,41 @@ test("trigger(type, [data], [fn])", function() {
form.remove();
});

test( "submit event bubbles on copied forms (#11649)", function(){
expect( 3 );

var $formByClone, $formByHTML,
$testForm = jQuery("#testForm"),
$fixture = jQuery("#qunit-fixture"),
$wrapperDiv = jQuery("<div/>").appendTo( $fixture );

function noSubmit( e ) {
e.preventDefault();
}
function delegatedSubmit() {
ok( true, "Make sure submit event bubbles up." );
return false;
}

// Attach a delegated submit handler to the parent element
$fixture.on( "submit", "form", delegatedSubmit );

// Trigger form submission to introduce the _submit_attached property
$testForm.on( "submit", noSubmit ).find("input[name=sub1]").click();

// Copy the form via .clone() and .html()
$formByClone = $testForm.clone( true, true ).removeAttr("id");
$formByHTML = jQuery( $fixture.html() ).filter("#testForm").removeAttr("id");
$wrapperDiv.append( $formByClone, $formByHTML );

// Check submit bubbling on the copied forms
$wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").click();

// Clean up
$wrapperDiv.remove();

This comment has been minimized.

Copy link
@MoonScript

MoonScript May 18, 2012

Author Contributor

Need to add one more clean-up item here as well:

$testForm.off( "submit", noSubmit );

This comment has been minimized.

Copy link
@dmethvin

dmethvin May 18, 2012

Member

Yep, I noticed I'd forgotten that when I got back to the ticket. Thanks!

$fixture.off( "submit", "form", delegatedSubmit );
});

test("trigger(eventObject, [data], [fn])", function() {
expect(28);

0 comments on commit e93f2a8

Please sign in to comment.
You can’t perform that action at this time.