Angular checkboxes example
Trying to make it work with required
by manikantag
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
<div ng-controller="myCtrl">
<ng-form name="myForm">
<span ng-repeat="choice in choices">
<label class="checkbox" for="{{choice.id}}">
<input type="checkbox" value="{{choice.id}}" ng-click="updateQuestionValue(choice)" ng-model="choice.checked" name="group-one" id="{{choice.id}}" />
{{choice.label}}
</label>
</span>
<input type="submit" value="Send" ng-click="submitSurvey(survey)" ng-disabled="value.length==0" />
</ng-form>
</div>
JavaScript
function myCtrl($scope) {
$scope.choices = [{"id":1, "value":"1", "label":"Good"}, {"id":2, "value":"2","label":"Ok"},{"id":3, "value":"3","label":"Bad"}];
$scope.value = [];
$scope.updateQuestionValue = function(choice){
$scope.value = $scope.value || [];
if(choice.checked){
$scope.value.push(choice.value);
$scope.value = _.uniq($scope.value);
}else{
$scope.value = _.without($scope.value, choice.value);
}
};
}