Skip to content

Commit

Permalink
Core: Do not search the whole DOM for radio/checkbox elements
Browse files Browse the repository at this point in the history
Fixes #1056
Closes #1064
  • Loading branch information
staabm authored and jzaefferer committed Feb 17, 2015
1 parent 60dd410 commit 64d6d7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -582,7 +582,7 @@ $.extend( $.validator, {
type = element.type;

if ( type === "radio" || type === "checkbox" ) {
return $( "input[name='" + element.name + "']:checked" ).val();
return this.findByName( element.name ).filter(":checked").val();
} else if ( type === "number" && typeof element.validity !== "undefined" ) {
return element.validity.badInput ? false : $element.val();
}
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Expand Up @@ -748,6 +748,13 @@ test( "findLastActive()", function() {
equal( v.lastActive, lastActive );
});

test("elementValue() finds radios/checkboxes only within the current form", function() {
expect(1);
var v = $("#userForm").validate(), foreignRadio = $("#radio2")[0];

ok( !v.elementValue(foreignRadio) );
});

test( "validating multiple checkboxes with 'required'", function() {
expect( 3 );
var checkboxes = $( "#form input[name=check3]" ).prop( "checked", false ),
Expand Down

0 comments on commit 64d6d7f

Please sign in to comment.