@@ -26,6 +26,7 @@ import {
2626import { environment } from '../../../environments/environment' ;
2727import { AppState } from '../../app.reducer' ;
2828import {
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