I'm currently defining a model driven form with formBuilder. In this form there is a radio button. And if the value of this radio button is true then I want to display additional inputs which only then are required.
If the radio is false then the additional inputs can be empty and must not block form submit.
Here is the formbuilder part, how can I make my scenario work?
initDynamicForm() {
let name = '';
let moreData = false;
let email = '';
this.dynamicForm = this.formBuilder.group({
name: [ name, Validators.required ],
moreData: moreData,
email: email // HERE: if moreData is true => must be required
});
}
Any idea on how to set this dynamically defined Validators.required on email input depending on moreData value?
Fact to mention: dynamicForm is called several times inside a *ngFor loop. Thus I can't defined component level attributes to be used because each form using dynamicForm "template" must work independently.