Skip to content

Commit efb88bd

Browse files
[DSC-2599] fix error clearing on blur
1 parent 06ae360 commit efb88bd

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/app/shared/form/form.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ describe('FormService test suite', () => {
278278

279279
service.removeErrorFromField(control, model, 'error.required');
280280

281-
expect(control.errors).toEqual({ required: null });
281+
expect(control.errors).toEqual(null);
282282
});
283283

284284
it('should remove errors from fields of concat group', () => {
@@ -300,7 +300,7 @@ describe('FormService test suite', () => {
300300

301301
// the group's inputs should no longer have an error
302302
Object.values(control.controls).forEach((subControl: AbstractControl) => {
303-
expect(control.errors).toEqual({ [messageKey]: null });
303+
expect(control.errors).toEqual(null);
304304
});
305305
});
306306

src/app/shared/form/form.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { environment } from '../../../environments/environment';
2727
import { AppState } from '../../app.reducer';
2828
import {
29+
hasValue,
2930
isEmpty,
3031
isNotUndefined,
3132
} from '../empty.util';
@@ -53,7 +54,7 @@ export class FormService {
5354
constructor(
5455
private formBuilderService: FormBuilderService,
5556
private store: Store<AppState>,
56-
private trnslateService: TranslateService) {
57+
private translateService: TranslateService) {
5758
}
5859

5960
/**
@@ -164,7 +165,7 @@ export class FormService {
164165
.map((errorKey) => {
165166
const defaultErrorKey = `error.validation.${errorKey}`;
166167
const customErrorKey = `error.validation.${formId}.${errorKey}`;
167-
const hasDefaultLabel = this.trnslateService.instant(defaultErrorKey) !== defaultErrorKey;
168+
const hasDefaultLabel = this.translateService.instant(defaultErrorKey) !== defaultErrorKey;
168169
return hasDefaultLabel ? defaultErrorKey : customErrorKey;
169170
});
170171
errors.forEach((error) => this.addError(formId, fieldId, fieldIndex, error));
@@ -211,7 +212,7 @@ export class FormService {
211212
error[errorKey] = null;
212213
const updatedError = { ...field.errors, ...error };
213214
field.setErrors(updatedError);
214-
field.setValidators(() => updatedError);
215+
field.clearValidators();
215216
field.updateValueAndValidity();
216217
}
217218

@@ -224,9 +225,10 @@ export class FormService {
224225
});
225226
}
226227

227-
const hasDifferentErrors = Object.keys(field.errors).filter((key) => field.errors[key]).length > 0;
228+
const currentErrors = field.errors;
229+
const hasDifferentErrors = hasValue(currentErrors) && Object.keys(currentErrors).filter((key) => currentErrors[key]).length > 0;
228230

229-
if (isEmpty(field.errors) || !hasDifferentErrors) {
231+
if (!hasDifferentErrors) {
230232
field.markAsUntouched();
231233
}
232234

0 commit comments

Comments
 (0)