Skip to content

Fixes issue 401 which causes error when nested form created programatica... #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jquery.validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ $.extend($.validator, {
console.error( "%o has no name assigned", this);
}

// ignore elements of nested forms
if ( this.form !== validator.currentForm ) {
return false;
}

// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ <h3></h3>
<input id="bypassSubmitWithNoValidate1" type="submit" formnovalidate value="bypass1"/>
<input id="bypassSubmitWithNoValidate2" type="submit" formnovalidate="formnovalidate" value="bypass2"/>
</form>

<form id="enclosingForm">
<input type="text" name="uname" class="required" />
</form>
</div>

</body>
Expand Down
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,18 @@ test('bypassing validation on form submission',function () {
equal($v.numberOfInvalids(), 1, "Validation failed correctly");
});

test("elements() should ignore elements of nested forms", function() {
var validator,
$form = $( "#enclosingForm" );

$( "<form id='nestedForm-1'><input type='text' name='nested-uname-1' /></form> " ).appendTo( $form );
$( "<form id='nestedForm-2'><input type='text' name='nested-uname-2' /></form> " ).appendTo( $form );
$form[ 0 ].uname.value = "Test";

validator = $form.validate();

equal( validator.elements().length, 1, "Elements of nested forms are ignored" );
});

module("misc");

Expand Down