@@ -375,7 +375,8 @@ $.extend( $.validator, {
375
375
this . invalid = { } ;
376
376
this . reset ( ) ;
377
377
378
- var groups = ( this . groups = { } ) ,
378
+ var currentForm = this . currentForm ,
379
+ groups = ( this . groups = { } ) ,
379
380
rules ;
380
381
$ . each ( this . settings . groups , function ( key , value ) {
381
382
if ( typeof value === "string" ) {
@@ -398,6 +399,12 @@ $.extend( $.validator, {
398
399
this . name = $ ( this ) . attr ( "name" ) ;
399
400
}
400
401
402
+ // Ignore the element if it belongs to another form. This will happen mainly
403
+ // when setting the `form` attribute of an input to the id of another form.
404
+ if ( currentForm !== this . form ) {
405
+ return ;
406
+ }
407
+
401
408
var validator = $ . data ( this . form , "validator" ) ,
402
409
eventType = "on" + event . type . replace ( / ^ v a l i d a t e / , "" ) ,
403
410
settings = validator . settings ;
@@ -631,6 +638,11 @@ $.extend( $.validator, {
631
638
this . name = name ;
632
639
}
633
640
641
+ // Ignore elements that belong to other/nested forms
642
+ if ( this . form !== validator . currentForm ) {
643
+ return false ;
644
+ }
645
+
634
646
// Select only the first element for each name, and only those with rules specified
635
647
if ( name in rulesCache || ! validator . objectLength ( $ ( this ) . rules ( ) ) ) {
636
648
return false ;
0 commit comments