mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2026-06-12 15:37:05 +02:00
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:
+12
-4
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user