I have this code for checkbox and below I want to validate these checkboxes by selecting at least 1 checked. It looks like the required is not working in this case. Any ideas?
I’m appreciated you feedback.
<ion-checkbox name="routine" ng-repeat="item in routines"
ng-model="item.checked"
ng-checked="item.checked"
ng-required="true">
{{ item.name }}
</ion-checkbox>
Please ignore this. The ng-required mainly is for the checkboxes that you need to select all of them. If you need to check only minimum you have to do different way which is:
setup on these in the controller:
$scope.routineCount = 0;
$scope.routineCheck = function(routine) {
if(routine.checked){
$scope.routineCount--;//opposite
}else{
$scope.routineCount++;
}
console.log('routineCount: ' + routineCount);
};
then in your html:
<label class="item item-input">Routines</label>
<ion-checkbox name="routine" ng-repeat="item in routines"
ng-model="item.checked"
ng-checked="item.checked"
ng-change="routineCheck(item)">
{{ item.name }}
</ion-checkbox>
<span class="error text-danger" ng-show="routineCount==0">* checked one routine at least</span>
<button class="button button-full button-positive" ng-disabled="programAddForm.$invalid || routineCount==0">Save</button>