@@ -8,7 +8,7 @@ import { AppState } from '../../app.reducer';
88import { formObjectFromIdSelector } from './selectors' ;
99import { FormBuilderService } from './builder/form-builder.service' ;
1010import { DynamicFormControlEvent , DynamicFormControlModel , DynamicFormGroupModel } from '@ng-dynamic-forms/core' ;
11- import { isEmpty , isNotUndefined } from '../empty.util' ;
11+ import { hasValue , isEmpty , isNotUndefined } from '../empty.util' ;
1212import uniqueId from 'lodash/uniqueId' ;
1313import {
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