diff options
Diffstat (limited to 'client/src/app/shared/forms/form-reactive.ts')
-rw-r--r-- | client/src/app/shared/forms/form-reactive.ts | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/client/src/app/shared/forms/form-reactive.ts b/client/src/app/shared/forms/form-reactive.ts index a5732e083..e7764d069 100644 --- a/client/src/app/shared/forms/form-reactive.ts +++ b/client/src/app/shared/forms/form-reactive.ts | |||
@@ -1,38 +1,38 @@ | |||
1 | import { FormGroup } from '@angular/forms'; | 1 | import { FormGroup } from '@angular/forms' |
2 | 2 | ||
3 | export abstract class FormReactive { | 3 | export abstract class FormReactive { |
4 | abstract form: FormGroup; | 4 | abstract form: FormGroup |
5 | abstract formErrors: Object; | 5 | abstract formErrors: Object |
6 | abstract validationMessages: Object; | 6 | abstract validationMessages: Object |
7 | 7 | ||
8 | abstract buildForm(): void; | 8 | abstract buildForm (): void |
9 | 9 | ||
10 | protected onValueChanged(data?: any) { | 10 | protected onValueChanged (data?: any) { |
11 | for (const field in this.formErrors) { | 11 | for (const field in this.formErrors) { |
12 | // clear previous error message (if any) | 12 | // clear previous error message (if any) |
13 | this.formErrors[field] = ''; | 13 | this.formErrors[field] = '' |
14 | const control = this.form.get(field); | 14 | const control = this.form.get(field) |
15 | 15 | ||
16 | if (control && control.dirty && !control.valid) { | 16 | if (control && control.dirty && !control.valid) { |
17 | const messages = this.validationMessages[field]; | 17 | const messages = this.validationMessages[field] |
18 | for (const key in control.errors) { | 18 | for (const key in control.errors) { |
19 | this.formErrors[field] += messages[key] + ' '; | 19 | this.formErrors[field] += messages[key] + ' ' |
20 | } | 20 | } |
21 | } | 21 | } |
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | // Same as onValueChanged but force checking even if the field is not dirty | 25 | // Same as onValueChanged but force checking even if the field is not dirty |
26 | protected forceCheck() { | 26 | protected forceCheck () { |
27 | for (const field in this.formErrors) { | 27 | for (const field in this.formErrors) { |
28 | // clear previous error message (if any) | 28 | // clear previous error message (if any) |
29 | this.formErrors[field] = ''; | 29 | this.formErrors[field] = '' |
30 | const control = this.form.get(field); | 30 | const control = this.form.get(field) |
31 | 31 | ||
32 | if (control && !control.valid) { | 32 | if (control && !control.valid) { |
33 | const messages = this.validationMessages[field]; | 33 | const messages = this.validationMessages[field] |
34 | for (const key in control.errors) { | 34 | for (const key in control.errors) { |
35 | this.formErrors[field] += messages[key] + ' '; | 35 | this.formErrors[field] += messages[key] + ' ' |
36 | } | 36 | } |
37 | } | 37 | } |
38 | } | 38 | } |