diff --git a/src/core.js b/src/core.js index 74d195e42..93fe25568 100644 --- a/src/core.js +++ b/src/core.js @@ -375,7 +375,8 @@ $.extend( $.validator, { this.invalid = {}; this.reset(); - var groups = ( this.groups = {} ), + var currentForm = this.currentForm, + groups = ( this.groups = {} ), rules; $.each( this.settings.groups, function( key, value ) { if ( typeof value === "string" ) { @@ -398,6 +399,12 @@ $.extend( $.validator, { this.name = $( this ).attr( "name" ); } + // Ignore the element if it belongs to another form. This will happen mainly + // when setting the `form` attribute of an input to the id of another form. + if ( currentForm !== this.form ) { + return; + } + var validator = $.data( this.form, "validator" ), eventType = "on" + event.type.replace( /^validate/, "" ), settings = validator.settings; @@ -631,6 +638,11 @@ $.extend( $.validator, { this.name = name; } + // Ignore elements that belong to other/nested forms + if ( this.form !== validator.currentForm ) { + return false; + } + // Select only the first element for each name, and only those with rules specified if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) { return false; diff --git a/test/index.html b/test/index.html index 3235689da..0079aa7d9 100644 --- a/test/index.html +++ b/test/index.html @@ -113,7 +113,7 @@
- + +