Core: Reset element styles when using custom highlight methods

When use a custom highlight functions which for example place the error
class in a different element (like Bootstrap form-group wrapper) this
element are not unhighlighted after resetForm.

Closes #1323
This commit is contained in:
Maks
2014-11-10 16:33:54 +01:00
committed by Jörn Zaefferer
parent f94ecf3cf0
commit 535033dbd4
2 changed files with 36 additions and 4 deletions
+12 -4
View File
@@ -455,10 +455,18 @@ $.extend( $.validator, {
this.lastElement = null;
this.prepareForm();
this.hideErrors();
this.elements()
.removeClass( this.settings.errorClass )
.removeData( "previousValue" )
.removeAttr( "aria-invalid" );
var i, elements = this.elements()
.removeData( "previousValue" )
.removeAttr( "aria-invalid" );
if ( this.settings.unhighlight ) {
for ( i = 0; elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ],
this.settings.errorClass, "" );
}
} else {
elements.removeClass( this.settings.errorClass );
}
},
numberOfInvalids: function() {
+24
View File
@@ -810,12 +810,36 @@ test( "resetForm()", function() {
var v = $( "#testForm1" ).validate();
v.form();
errors( 2 );
ok( $( "#firstname" ).hasClass( "error" ) );
$( "#firstname" ).val( "hiy" );
v.resetForm();
errors( 0 );
ok( !$( "#firstname" ).hasClass( "error" ) );
equal( "", $( "#firstname" ).val(), "form plugin is included, therefor resetForm must also reset inputs, not only errors" );
});
test( "resetForm() clean styles when custom highlight function is used", function() {
var form = $( "#testForm1clean" ),
e = $( "#firstnamec" );
form.validate({
highlight: function( element ) {
$( element ).hide();
},
unhighlight: function( element ) {
$( element ).show();
},
ignore: "",
errorClass: "invalid",
rules: {
firstnamec: "required"
}
});
e.valid();
ok( !e.is( ":visible" ) );
form.validate().resetForm();
ok( e.is( ":visible" ) );
});
test( "message from title", function() {
var v = $( "#withTitle" ).validate();
v.checkForm();