Skip to content

Commit 214751b

Browse files
authored
fix(form): simplify blur and respect revalidation
The validation triggered by change and blur are similar. However, the code was unneccesary different. Additionally the blur validation did not respect a possible given revalidate:false resulting in revalidating error fields all the time when the field blurs (even if one only wants revalidation on submit) It also fixes not showing/updating the error messages on blur as change does
1 parent 185e234 commit 214751b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/definitions/behaviors/form.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,11 @@ $.fn.form = function(parameters) {
444444
$fieldGroup = $field.closest($group),
445445
validationRules = module.get.validation($field)
446446
;
447-
if( $fieldGroup.hasClass(className.error) ) {
447+
if(validationRules && (settings.on == 'blur' || ( $fieldGroup.hasClass(className.error) && settings.revalidate) )) {
448448
module.debug('Revalidating field', $field, validationRules);
449-
if(validationRules) {
450-
module.validate.field( validationRules );
451-
}
452-
}
453-
else if(settings.on == 'blur') {
454-
if(validationRules) {
455-
module.validate.field( validationRules );
449+
module.validate.field( validationRules );
450+
if(!settings.inline) {
451+
module.validate.form(false,true);
456452
}
457453
}
458454
},
@@ -465,7 +461,7 @@ $.fn.form = function(parameters) {
465461
if(validationRules && (settings.on == 'change' || ( $fieldGroup.hasClass(className.error) && settings.revalidate) )) {
466462
clearTimeout(module.timer);
467463
module.timer = setTimeout(function() {
468-
module.debug('Revalidating field', $field, module.get.validation($field));
464+
module.debug('Revalidating field', $field, validationRules);
469465
module.validate.field( validationRules );
470466
if(!settings.inline) {
471467
module.validate.form(false,true);

0 commit comments

Comments
 (0)