I have a reactive form with a dynamic form array. There is a button to add new objects to the form. However, I only want this button to be "enabled" when the current object in the array has been populated/or is already populated.
<div *ngIf="form">
<form [formGroup]="form">
<div formArrayName="justificationItems">
<div *ngFor="let orgs of form.controls['justificationItems']?.controls; let i = index"
[formGroupName]="i">
<input formControlName="name" placeholder="Item name">
<input formControlName="description" placeholder="Item description">
<input formControlName="code" placeholder="Item price">
</div>
<button [disabled]="!form.controls['justificationItems']?.controls.description" type="button" (click)="addItem()">Add Item</button>
</div>
</form>
</div>
I need to add the attribute of disabled based on 3 fields to look to see if they are empty. I tried this with one field to start with:
[disabled]="!form.controls['justificationItems']?.controls.description"
I thought the above would look at the description fields and see if it has value.
Any alternative methods welcome. I think the issue is that it needs to look at an array item.