vendredi 6 décembre 2019

Is there a way to reset the rest of the checkbox item when clicking 'None of the above option' in Angular?

I've been struggling with reactive forms with checkboxes .

  1. If none of the items is selected , submit button should be disabled . This is done

  2. There's an option called "None of the above" . Selecting this should unselect all the selected items(if any) in the checkboxes

  3. 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