]> source.dussan.org Git - jquery.git/commitdiff
Fix #11649. Preserve oldIE submit flag when cloning, closes gh-772.
authorJason Moon <jmoon@socialcast.com>
Fri, 18 May 2012 20:30:28 +0000 (16:30 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 18 May 2012 20:34:30 +0000 (16:34 -0400)
src/event.js
src/manipulation.js
test/unit/event.js

index 6351d0b53e9a577e846c725ea1d608736a905e1d..458eafbc2b6dccad95793bb8cdc377079016cb63 100644 (file)
@@ -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
index 8b338a5b4e480c1c102051a1a40acbfbe2167552..ee5a84c51483e7c3c6522cb528921d5c4c2fc336 100644 (file)
@@ -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" );
 }
 
index d5582190a999558a3ef1f5a061eb376730434399..32980cd59f1c89b5689490d22d096ec805e0609a 100644 (file)
@@ -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();
+       $fixture.off( "submit", "form", delegatedSubmit );
+});
+
 test("trigger(eventObject, [data], [fn])", function() {
        expect(28);