aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/form-reactive.ts
blob: d1e7be8026fe206ba13acefd2f752160b4c21e0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { FormGroup } from '@angular/forms'
import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model'
import { FormReactiveService, FormReactiveValidationMessages } from './form-reactive.service'

export abstract class FormReactive {
  protected abstract formReactiveService: FormReactiveService
  protected formChanged = false

  form: FormGroup
  formErrors: any // To avoid casting in template because of string | FormReactiveErrors
  validationMessages: FormReactiveValidationMessages

  buildForm (obj: BuildFormArgument, defaultValues: BuildFormDefaultValues = {}) {
    const { formErrors, validationMessages, form } = this.formReactiveService.buildForm(obj, defaultValues)

    this.form = form
    this.formErrors = formErrors
    this.validationMessages = validationMessages
  }

  protected async waitPendingCheck () {
    return this.formReactiveService.waitPendingCheck(this.form)
  }

  protected markAllAsDirty () {
    return this.formReactiveService.markAllAsDirty(this.form.controls)
  }

  protected forceCheck () {
    return this.formReactiveService.forceCheck(this.form, this.formErrors, this.validationMessages)
  }
}