I've been struggling with reactive forms with checkboxes .
-
If none of the items is selected , submit button should be disabled . This is done
-
There's an option called "None of the above" . Selecting this should unselect all the selected items(if any) in the checkboxes
- Selecting back any item but 'None of the above' should unselect the 'None of the above'
HTML
<form [formGroup]="form" (ngSubmit)="submit()">
<label formArrayName="orders" *ngFor="let order of form.controls.orders.controls; let i = index">
<input type="checkbox" [formControlName]="i" (click)="onChange(orderData)">
</label>
<br>
<button [disabled]="!form.valid">submit</button>
</form>
TS
onChange(event) {
console.log(event);
}
You can find complete code related to this on StackBlitz.
Aucun commentaire:
Enregistrer un commentaire