Skip to content

Commit a355a0f

Browse files
committed
Core: Ignore elements that belong to other/nested forms
Ref jquery-validation#704 Ref jquery-validation#1970 Fixes jquery-validation#2035
1 parent 8769eab commit a355a0f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/core.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ $.extend( $.validator, {
375375
this.invalid = {};
376376
this.reset();
377377

378-
var groups = ( this.groups = {} ),
378+
var currentForm = this.currentForm,
379+
groups = ( this.groups = {} ),
379380
rules;
380381
$.each( this.settings.groups, function( key, value ) {
381382
if ( typeof value === "string" ) {
@@ -398,6 +399,12 @@ $.extend( $.validator, {
398399
this.name = $( this ).attr( "name" );
399400
}
400401

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+
401408
var validator = $.data( this.form, "validator" ),
402409
eventType = "on" + event.type.replace( /^validate/, "" ),
403410
settings = validator.settings;
@@ -631,6 +638,11 @@ $.extend( $.validator, {
631638
this.name = name;
632639
}
633640

641+
// Ignore elements that belong to other/nested forms
642+
if ( this.form !== validator.currentForm ) {
643+
return false;
644+
}
645+
634646
// Select only the first element for each name, and only those with rules specified
635647
if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
636648
return false;

0 commit comments

Comments
 (0)