#Hi, How do I prevent the save button if the checkbox is unchecked?
14 messages · Page 1 of 1 (latest)
Bound button's [disabled] property to the inverse of checkbox' [checked] one.
declare something like...
[(disabled)]="checked"
Hi @drowsy rapids, welcome to 
We recommend you start your Angular journey with the Tour of Heroes tutorial, located here: https://angular.io/tutorial.
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>
the save button is still frozen with above code
i've set checked to false in the component
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>
that worked...how did you figure that out?
It was an error of mine in the beginning.
how did you know we need bulkCompanyService.allFutureCompanies in the disabled attribute?
Because it's the same model bound to the checkbox.