diff options
Diffstat (limited to 'client/src/app/shared/shared-forms/form-validator.service.ts')
-rw-r--r-- | client/src/app/shared/shared-forms/form-validator.service.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/client/src/app/shared/shared-forms/form-validator.service.ts b/client/src/app/shared/shared-forms/form-validator.service.ts index 897008242..14ee044b5 100644 --- a/client/src/app/shared/shared-forms/form-validator.service.ts +++ b/client/src/app/shared/shared-forms/form-validator.service.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { AsyncValidatorFn, FormArray, FormBuilder, FormControl, FormGroup, ValidatorFn } from '@angular/forms' | 2 | import { AsyncValidatorFn, FormArray, FormBuilder, FormControl, FormGroup, ValidatorFn } from '@angular/forms' |
3 | import { objectKeysTyped } from '@shared/core-utils' | ||
3 | import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model' | 4 | import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model' |
4 | import { FormReactiveErrors, FormReactiveValidationMessages } from './form-reactive.service' | 5 | import { FormReactiveErrors, FormReactiveValidationMessages } from './form-reactive.service' |
5 | 6 | ||
@@ -47,13 +48,14 @@ export class FormValidatorService { | |||
47 | obj: BuildFormArgument, | 48 | obj: BuildFormArgument, |
48 | defaultValues: BuildFormDefaultValues = {} | 49 | defaultValues: BuildFormDefaultValues = {} |
49 | ) { | 50 | ) { |
50 | for (const name of Object.keys(obj)) { | 51 | for (const name of objectKeysTyped(obj)) { |
51 | formErrors[name] = '' | 52 | formErrors[name] = '' |
52 | 53 | ||
53 | const field = obj[name] | 54 | const field = obj[name] |
54 | if (this.isRecursiveField(field)) { | 55 | if (this.isRecursiveField(field)) { |
55 | this.updateFormGroup( | 56 | this.updateFormGroup( |
56 | form[name], | 57 | // FIXME: typings |
58 | (form as any)[name], | ||
57 | formErrors[name] as FormReactiveErrors, | 59 | formErrors[name] as FormReactiveErrors, |
58 | validationMessages[name] as FormReactiveValidationMessages, | 60 | validationMessages[name] as FormReactiveValidationMessages, |
59 | obj[name] as BuildFormArgument, | 61 | obj[name] as BuildFormArgument, |
@@ -67,7 +69,7 @@ export class FormValidatorService { | |||
67 | const defaultValue = defaultValues[name] || '' | 69 | const defaultValue = defaultValues[name] || '' |
68 | 70 | ||
69 | form.addControl( | 71 | form.addControl( |
70 | name, | 72 | name + '', |
71 | new FormControl(defaultValue, field?.VALIDATORS as ValidatorFn[], field?.ASYNC_VALIDATORS as AsyncValidatorFn[]) | 73 | new FormControl(defaultValue, field?.VALIDATORS as ValidatorFn[], field?.ASYNC_VALIDATORS as AsyncValidatorFn[]) |
72 | ) | 74 | ) |
73 | } | 75 | } |
@@ -75,7 +77,8 @@ export class FormValidatorService { | |||
75 | 77 | ||
76 | updateTreeValidity (group: FormGroup | FormArray): void { | 78 | updateTreeValidity (group: FormGroup | FormArray): void { |
77 | for (const key of Object.keys(group.controls)) { | 79 | for (const key of Object.keys(group.controls)) { |
78 | const abstractControl = group.controls[key] as FormControl | 80 | // FIXME: typings |
81 | const abstractControl = (group.controls as any)[key] as FormControl | ||
79 | 82 | ||
80 | if (abstractControl instanceof FormGroup || abstractControl instanceof FormArray) { | 83 | if (abstractControl instanceof FormGroup || abstractControl instanceof FormArray) { |
81 | this.updateTreeValidity(abstractControl) | 84 | this.updateTreeValidity(abstractControl) |