DEV Community

Discussion on: Parametrized Validators in Dynamic Forms

Collapse
 
dnmakarov profile image
dnmakarov • Edited

Hey, thanks for the great article.

My question is can we apply validators to the FormGroup e.g.

formGroup = new FormGroup(
  { ...fields }, 
  { validators: [ ...someCustomValidators ] }
);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
matheo profile image
Mateo Tibaquirá

Yes, every DynControl is able to have its Validators but in the Config type structure:

{
  options: { validators: [...someCustomValidators] },
  controls: [ ..fieldsConfigs ]
}
Enter fullscreen mode Exit fullscreen mode

I'm improving the typing of the Config right now to detect inline ValidatorFn in case we don't want to provide them via id and just want to build a fast prototype :)