1
votes

I have a custom control using ControlValueAccessor, and my control is in a form with a bunch of material input controls.

The material inputs show the red validation underline in 3 cases.

  1. the control has been touched and is invalid
  2. the control is dirty and invalid
  3. the form containing the control has been submitted and the control is invalid

I want to mimic this behavior in my custom control. I've used the injector to get a reference to the NgControl which lets me determine if the control is touched/dirty and invalid. But I can't figure out how to access the parent NgForm in a generic way to determine if it is submitted.

I don't want to explicitly pass it into my component, and I shouldn't need to since it isn't being explicitly passed to material input either yet that control is able to determine if the form has been submitted.

How do I get a hold of the parent forms submitted state?

1

1 Answers

1
votes

I ended up finding it in the injector, had to grab the FormGroupDirective

const formgroup: FormGroupDirective = this.injector.get(FormGroupDirective, null);

The directive has a submitted property I was able to use