Reputation: 209
How to validate this checkboxes, at least one must be checked, if not, there has to be some message or alert
<div class="form-group" ng-class="{ 'has-error' : actionsAddForm.active.$invalid && !actionsAddForm.active.$pristine }">
<label class="control-label col-sm-2">Days*</label>
<div class="col-sm-10">
<label>Monday
<input type="checkbox" ng-model="actions.value1">
</label>
<label>Tuesday
<input type="checkbox" ng-model="actions.value2">
</label>
<label>Wednesday
<input type="checkbox" ng-model="actions.value3">
</label>
<label>Thursday
<input type="checkbox" ng-model="actions.value4">
</label>
<label>Friday
<input type="checkbox" ng-model="actions.value5">
</label>
<label>Saturday
<input type="checkbox" ng-model="actions.value6">
</label>
<label>Sunday
<input type="checkbox" ng-model="actions.value7">
</label>
</div>
Upvotes: 1
Views: 58
Reputation: 11388
This can be done :
<div ng-hide="actions.value1 || actions.value2 || actions.value3...">
You have an error
</div>
Otherwise, if you want to be able to use $valid,... You will have to create a custom directive inheriting from ngModelController, and adding your custom validators inside : https://docs.angularjs.org/api/ng/type/ngModel.NgModelController
Upvotes: 1