diff options
Diffstat (limited to 'client/src/app/shared/shared-forms/form-reactive.ts')
-rw-r--r-- | client/src/app/shared/shared-forms/form-reactive.ts | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/client/src/app/shared/shared-forms/form-reactive.ts b/client/src/app/shared/shared-forms/form-reactive.ts index f2ce82360..30b59c141 100644 --- a/client/src/app/shared/shared-forms/form-reactive.ts +++ b/client/src/app/shared/shared-forms/form-reactive.ts | |||
@@ -56,13 +56,18 @@ export abstract class FormReactive { | |||
56 | 56 | ||
57 | if (control.dirty) this.formChanged = true | 57 | if (control.dirty) this.formChanged = true |
58 | 58 | ||
59 | // Don't care if dirty on force check | 59 | if (forceCheck) control.updateValueAndValidity({ emitEvent: false }) |
60 | const isDirty = control.dirty || forceCheck === true | 60 | if (!control || !control.dirty || !control.enabled || control.valid) continue |
61 | if (control && isDirty && control.enabled && !control.valid) { | 61 | |
62 | const messages = validationMessages[field] | 62 | const staticMessages = validationMessages[field] |
63 | for (const key of Object.keys(control.errors)) { | 63 | for (const key of Object.keys(control.errors)) { |
64 | formErrors[field] += messages[key] + ' ' | 64 | const formErrorValue = control.errors[key] |
65 | } | 65 | |
66 | // Try to find error message in static validation messages first | ||
67 | // Then check if the validator returns a string that is the error | ||
68 | if (typeof formErrorValue === 'boolean') formErrors[field] += staticMessages[key] + ' ' | ||
69 | else if (typeof formErrorValue === 'string') formErrors[field] += control.errors[key] | ||
70 | else throw new Error('Form error value of ' + field + ' is invalid') | ||
66 | } | 71 | } |
67 | } | 72 | } |
68 | } | 73 | } |