Skip to content

Commit 33397cc

Browse files
authored
fix(form): isvalid should not delete error state and made optional now
the is valid behavior deletes possible existing error states on a field, although it shouldn't. That's because the field validator always removes the error state by default (before probably adding it again) and did not respect a showErrors setting. showErrors however is only meant to show new errors. If it is false it should not touch any existing error state class. I now also added the showErrors parameter as an option to the is valid behavior in case someone definately wants to show errors on not already validated fields. As the parameter is optional the change is fully backwards compatible.
1 parent c8ad8b9 commit 33397cc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/definitions/behaviors/form.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,18 @@ $.fn.form = function(parameters) {
338338
blank: function($field) {
339339
return String($field.val()).trim() === '';
340340
},
341-
valid: function(field) {
341+
valid: function(field, showErrors) {
342342
var
343343
allValid = true
344344
;
345345
if(field) {
346346
module.verbose('Checking if field is valid', field);
347-
return module.validate.field(validation[field], field, false);
347+
return module.validate.field(validation[field], field, !!showErrors);
348348
}
349349
else {
350350
module.verbose('Checking if form is valid');
351351
$.each(validation, function(fieldName, field) {
352-
if( !module.is.valid(fieldName) ) {
352+
if( !module.is.valid(fieldName, showErrors) ) {
353353
allValid = false;
354354
}
355355
});
@@ -1235,7 +1235,9 @@ $.fn.form = function(parameters) {
12351235
module.debug('Field depends on another value that is not present or empty. Skipping', $dependsField);
12361236
}
12371237
else if(field.rules !== undefined) {
1238-
$field.closest($group).removeClass(className.error);
1238+
if(showErrors) {
1239+
$field.closest($group).removeClass(className.error);
1240+
}
12391241
$.each(field.rules, function(index, rule) {
12401242
if( module.has.field(identifier)) {
12411243
var invalidFields = module.validate.rule(field, rule,true) || [];

0 commit comments

Comments
 (0)