Extend ControlValueAccessor with isEmpty function

226 views Asked by At

i have a parent form with all subforms that implements ControlValueAccessor interface. I need then to validate the emptiness of these forms from the parent. The logic of the isEmpty changes in each form. I tried to extend the interface ControlValueAccessor with an isEmpty method, but what i see from the parent form are only standard FormControl childs without the isEmpty method.

Is there a way to do this?

1

There are 1 answers

0
Eliseo On

I mean that you need add as provider

providers: [
    {
      provide: NG_VALIDATORS,
      useExisting: YourComponent,
      multi: true
    }
  ]

And create a function validate

validate({ value }: FormControl) {
    ....
    return isNotValid?{invalid: true}:null
  }

Inside the custom Form Control. Then the control is invalid according this function validate independently you create the formControl with validators or not