1 import { FormGroup } from '@angular/forms'
3 export abstract class FormReactive {
4 abstract form: FormGroup
5 abstract formErrors: Object
6 abstract validationMessages: Object
8 abstract buildForm (): void
10 protected onValueChanged (data?: any) {
11 for (const field in this.formErrors) {
12 // clear previous error message (if any)
13 this.formErrors[field] = ''
14 const control = this.form.get(field)
16 if (control && control.dirty && !control.valid) {
17 const messages = this.validationMessages[field]
18 for (const key in control.errors) {
19 this.formErrors[field] += messages[key] + ' '
25 // Same as onValueChanged but force checking even if the field is not dirty
26 protected forceCheck () {
27 for (const field in this.formErrors) {
28 // clear previous error message (if any)
29 this.formErrors[field] = ''
30 const control = this.form.get(field)
32 if (control && !control.valid) {
33 const messages = this.validationMessages[field]
34 for (const key in control.errors) {
35 this.formErrors[field] += messages[key] + ' '