Permalink
Browse files

Core: Apply ignore setting to all validationTargetFor elements

Previously the filter only applied to checkables. Adds a test and moves
an existing valid() test closer to the others.

Ref #156
Closes #468
  • Loading branch information...
jzaefferer committed Sep 23, 2014
1 parent 8b2f1e0 commit f1c611ed7a38b56a337211cc2d9eee6a538765ea
Showing with 42 additions and 28 deletions.
  1. +6 −3 src/core.js
  2. +36 −25 test/test.js
View
@@ -821,11 +821,14 @@ $.extend( $.validator, {
},
validationTargetFor: function( element ) {
- // if radio/checkbox, validate first element in group instead
+
+ // If radio/checkbox, validate first element in group instead
if ( this.checkable( element ) ) {
- element = this.findByName( element.name ).not( this.settings.ignore )[ 0 ];
+ element = this.findByName( element.name );
}
- return element;
+
+ // Always apply ignore filter
+ return $( element ).not( this.settings.ignore )[ 0 ];
},
checkable: function( element ) {
View
@@ -105,6 +105,41 @@ test( "valid() plugin method, special handling for checkable groups", function()
ok( checkable.valid(), "valid, third box is checked" );
});
+test( "valid() ???", function() {
+ expect( 4 );
+ var errorList = [
+ {
+ name: "meal",
+ message: "foo",
+ element: $( "#meal" )[ 0 ]
+ }
+ ],
+ v = $( "#testForm3" ).validate();
+
+ ok( v.valid(), "No errors, must be valid" );
+ v.errorList = errorList;
+ ok( !v.valid(), "One error, must be invalid" );
+ QUnit.reset();
+ v = $( "#testForm3" ).validate({
+ submitHandler: function() {
+ ok( false, "Submit handler was called" );
+ }
+ });
+ ok( v.valid(), "No errors, must be valid and returning true, even with the submit handler" );
+ v.errorList = errorList;
+ ok( !v.valid(), "One error, must be invalid, no call to submit handler" );
+});
+
+test( "valid(), ignores ignored elements", function() {
+ $( "#testForm1clean" ).validate({
+ ignore: "#firstnamec",
+ rules: {
+ firstnamec: "required"
+ }
+ });
+ ok( $( "#firstnamec" ).valid() );
+});
+
test( "addMethod", function() {
expect( 3 );
$.validator.addMethod( "hi", function( value ) {
@@ -298,31 +333,6 @@ test( "hide(): container", function() {
ok( errorLabel.is( ":hidden" ), "Error label not visible after hiding it" );
});
-test( "valid()", function() {
- expect( 4 );
- var errorList = [
- {
- name: "meal",
- message: "foo",
- element: $( "#meal" )[ 0 ]
- }
- ],
- v = $( "#testForm3" ).validate();
-
- ok( v.valid(), "No errors, must be valid" );
- v.errorList = errorList;
- ok( !v.valid(), "One error, must be invalid" );
- QUnit.reset();
- v = $( "#testForm3" ).validate({
- submitHandler: function() {
- ok( false, "Submit handler was called" );
- }
- });
- ok( v.valid(), "No errors, must be valid and returning true, even with the submit handler" );
- v.errorList = errorList;
- ok( !v.valid(), "One error, must be invalid, no call to submit handler" );
-});
-
test( "submitHandler keeps submitting button", function() {
var button, event;
@@ -530,6 +540,7 @@ test( "option: (un)highlight, custom", function() {
equal( "invalid", errorClass );
$( element ).show();
},
+ ignore: "",
errorClass: "invalid",
rules: {
firstnamec: "required"

0 comments on commit f1c611e

Please sign in to comment.