#Hi, How do I prevent the save button if the checkbox is unchecked?

14 messages · Page 1 of 1 (latest)

drowsy rapids
#
<ui-modal

    <p>
      Updates will apply to {{ company.name }}, which will no longer be associated with the shared rule.
      <b>This action will unlink this company from any other shared rules associated with it.</b>
    </p>


</ui-modal>
upbeat bluff
#

Bound button's [disabled] property to the inverse of checkbox' [checked] one.

drowsy rapids
#

declare something like...

[(disabled)]="checked"
upbeat bluff
#

I suggest to you to follow official tutorial

#

g!toh @drowsy rapids

pallid belfryBOT
#

Hi @drowsy rapids, welcome to angular

We recommend you start your Angular journey with the Tour of Heroes tutorial, located here: https://angular.io/tutorial.

upbeat bluff
#

In the specific case, this should work

    <ui-checkbox #agreeChk
      class="u-margin-top-20 u-block"
      [(ngModel)]="bulkCompanyService.allFutureCompanies">
      I understand that this action cannot be undone. 
    </ui-checkbox>

    <div class="u-text-align-right">
      <button class="btn btn--tertiary u-margin-left-10" (click)="cancel()">Cancel</button>
      <button class="btn btn--primary" (click)="save()  
              [disabled]="!agreeChk.checked">Save</button>
    </div>
drowsy rapids
#

the save button is still frozen with above code

#

i've set checked to false in the component

upbeat bluff
#

Maybe it's binding to the checked attribute and not to the property.
You can use its model, tho.

    <ui-checkbox
      class="u-margin-top-20 u-block"
      [(ngModel)]="bulkCompanyService.allFutureCompanies">
      I understand that this action cannot be undone. 
    </ui-checkbox>

    <div class="u-text-align-right">
      <button class="btn btn--tertiary u-margin-left-10" (click)="cancel()">Cancel</button>
      <button class="btn btn--primary" (click)="save()  
              [disabled]="!bulkCompanyService.allFutureCompanies">Save</button>
    </div>
drowsy rapids
#

that worked...how did you figure that out?

upbeat bluff
#

It was an error of mine in the beginning.

drowsy rapids
#

how did you know we need bulkCompanyService.allFutureCompanies in the disabled attribute?

upbeat bluff
#

Because it's the same model bound to the checkbox.