Skip to content

Commit

Permalink
fix(validation): display errors on blur. (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad authored Nov 27, 2017
1 parent b3744ac commit 680f6a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/core/src/services/formly.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ describe('FormlyConfig service', () => {
});

describe('extra option: showError', () => {
it('should return true when form is submitted and form is invalid', () => {
it('should showError when form is submitted and form is invalid', () => {
const field = {},
formControl = new FormControl(null, Validators.required),
options = { parentForm: { submitted: true } };

expect(config.extras.showError({ options, formControl, field } as any)).toBeTruthy();
});
it('should showError when field is touched and form is invalid', () => {
const field = {},
formControl = new FormControl(null, Validators.required),
options = { parentForm: { submitted: false } };

formControl.markAsTouched();

expect(config.extras.showError({ options, formControl, field } as any)).toBeTruthy();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/services/formly.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FormlyConfig {
} = {
fieldTransform: undefined,
showError: function(field: Field) {
return (field.formControl.dirty || (field.options.parentForm && field.options.parentForm.submitted) || (field.field.validation && field.field.validation.show)) && field.formControl.invalid;
return (field.formControl.touched || field.formControl.dirty || (field.options.parentForm && field.options.parentForm.submitted) || (field.field.validation && field.field.validation.show)) && field.formControl.invalid;
},
};

Expand Down

0 comments on commit 680f6a3

Please sign in to comment.