Skip to content

Commit 95cb3b4

Browse files
[DSC-2599] fix error clearing on blur
1 parent ca48a46 commit 95cb3b4

2 files changed

Lines changed: 9 additions & 8 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
@@ -262,7 +262,7 @@ describe('FormService test suite', () => {
262262

263263
service.removeErrorFromField(control, model, 'error.required');
264264

265-
expect(control.errors).toEqual({ required: null });
265+
expect(control.errors).toEqual(null);
266266
});
267267

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

285285
// the group's inputs should no longer have an error
286286
Object.values(control.controls).forEach((subControl: AbstractControl) => {
287-
expect(control.errors).toEqual({ [messageKey]: null });
287+
expect(control.errors).toEqual(null);
288288
});
289289
});
290290

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AppState } from '../../app.reducer';
88
import { formObjectFromIdSelector } from './selectors';
99
import { FormBuilderService } from './builder/form-builder.service';
1010
import { DynamicFormControlEvent, DynamicFormControlModel, DynamicFormGroupModel } from '@ng-dynamic-forms/core';
11-
import { isEmpty, isNotUndefined } from '../empty.util';
11+
import { hasValue, isEmpty, isNotUndefined } from '../empty.util';
1212
import uniqueId from 'lodash/uniqueId';
1313
import {
1414
FormAddError,
@@ -30,7 +30,7 @@ export class FormService {
3030
constructor(
3131
private formBuilderService: FormBuilderService,
3232
private store: Store<AppState>,
33-
private trnslateService: TranslateService) {
33+
private translateService: TranslateService) {
3434
}
3535

3636
/**
@@ -141,7 +141,7 @@ export class FormService {
141141
.map((errorKey) => {
142142
const defaultErrorKey = `error.validation.${errorKey}`;
143143
const customErrorKey = `error.validation.${formId}.${errorKey}`;
144-
const hasDefaultLabel = this.trnslateService.instant(defaultErrorKey) !== defaultErrorKey;
144+
const hasDefaultLabel = this.translateService.instant(defaultErrorKey) !== defaultErrorKey;
145145
return hasDefaultLabel ? defaultErrorKey : customErrorKey;
146146
});
147147
errors.forEach((error) => this.addError(formId, fieldId, fieldIndex, error));
@@ -188,7 +188,7 @@ export class FormService {
188188
error[errorKey] = null;
189189
const updatedError = { ...field.errors, ...error };
190190
field.setErrors(updatedError);
191-
field.setValidators(() => updatedError);
191+
field.clearValidators();
192192
field.updateValueAndValidity();
193193
}
194194

@@ -201,9 +201,10 @@ export class FormService {
201201
});
202202
}
203203

204-
const hasDifferentErrors = Object.keys(field.errors).filter((key) => field.errors[key]).length > 0;
204+
const currentErrors = field.errors;
205+
const hasDifferentErrors = hasValue(currentErrors) && Object.keys(currentErrors).filter((key) => currentErrors[key]).length > 0;
205206

206-
if (isEmpty(field.errors) || !hasDifferentErrors) {
207+
if (!hasDifferentErrors) {
207208
field.markAsUntouched();
208209
}
209210

0 commit comments

Comments
 (0)