I have 5 checkboxes in a FormGroup, display using ngFor, and 1 matInput that has to be a required field if any of the checkboxes is checked.
.ts
this.gridForm = this.fb.group({
cbox1: [''],
cbox2: [''],
cbox3: [''],
cbox4: [''],
cbox5: [''],
input1: ['', Validators.required] });
.html
<div *ngFor="let table of xTables; let i = index;">
<mat-checkbox formControlName="{{xTableKeys[i]}}">{{table}}</mat-checkbox>
</div>
<mat-form-field>
<input matInput formControlName="xType" placeholder="X Type">
</mat-form-field>
I've added required validators for the input, but what I need is to make it required only after any of the checkboxes is checked. Current status is I cannot submit the form unless I fill in the input, but with or without checking the checkbox.