Core: Error hidden but input error class not removed

When a field has one rule with option `depends` specified and this
dependency mismatch, the plugin will remove it, so that field will not be
validated on submit by the the rule in question. So if that field is
already invalid, only the error message will be hidden and the error class
will remain.

This commit fixes this issue.

Fixes #1632
This commit is contained in:
Brahim Arkni
2015-11-11 23:07:17 +00:00
committed by Markus Staab
parent 9d00c2b9ff
commit ef6821aba3
3 changed files with 45 additions and 1 deletions

View File

@@ -407,3 +407,36 @@ test( "test id/name containing single quotes", function() {
equal( v.invalidElements()[ 1 ], checkboxElement[ 0 ], "The text element should be invalid" );
equal( v.invalidElements()[ 2 ], radioElement[ 0 ], "The text element should be invalid" );
} );
test( "#1632: Error hidden, but input error class not removed", function() {
var v = $( "#testForm23" ).validate( {
rules: {
box1: {
required: {
depends: function() {
return !!$( "#box2" ).val();
}
}
},
box2: {
required: {
depends: function() {
return !!$( "#box1" ).val();
}
}
}
}
} ),
box1 = $( "#box1" ),
box2 = $( "#box2" );
box1.val( "something" );
v.form();
equal( v.numberOfInvalids(), 1, "There is only one invlid element" );
equal( v.invalidElements()[ 0 ], box2[ 0 ], "The box2 element should be invalid" );
box1.val( "" );
v.form();
equal( v.numberOfInvalids(), 0, "There is no error" );
equal( box2.hasClass( "error" ), false, "Box2 should not have an error class" );
} );