I have a form with list of checkboxes, as shown here:
$scope.deviceList = [
{ text: "Dev 0", checked: false },
{ text: "Dev 1", checked: false },
{ text: "Dev 2", checked: false },
{ text: "Dev 3", checked: false },
{ text: "Dev 4", checked: false }
];
<form>
<ion-checkbox class="checkbox-balanced"
ng-repeat="item in deviceList"
ng-model="item.checked"
ng-required="true">
{{ item.text }}
</ion-checkbox>
</form>
Of course that I have more elements. but just for this case I show the relavent code.
Now, I would like to have a validation that the form cannot be sent until all checkboxes are checked. Any suggestions of an elegant solution for that?
Thanks in advance
Maybe a function with something like the following would do the trick:
$scope.validate = function(){
var numChecked = $filter($scope.deviceList, function(device) {
return device.checked
}).length;
return $scope.deviceList.length == numChecked;
}
And don't forget to inject $filter service in your controller or it won't work