我有一个名称传递给控制器的表单,当表单是$ valid时,我继续处理数据。这用于使用单选按钮,但是当我切换到复选框时,只有在选中所有复选框时才会通过验证。我怎样才能这样做,选择1使表格有效? 代码段供参考:
<form name="snippetForm" ng-submit="vm.submitForm(snippetForm)" novalidate>
<input type="checkbox" ng-model="vm.destination.1" ng-true-value="'1'" name="location" required >
<input type="checkbox" ng-model="vm.destination.2" ng-true-value="'2'" name="location" required >
<input type="checkbox" ng-model="vm.destination.3" ng-true-value="'3'" name="location" required >
</form>
vm.submitForm = function(form) {
if(form.$valid) {
console.log('Passes only when all checkboxes from form.location are selected')
}
}
答案 0 :(得分:0)
我在每个复选框上添加了class CollectionSerializer(serializers.ModelSerializer):
class Meta:
model = Collection
fields = ('id','title', 'nlikes')
表达式。如果没有选中复选框,表达式将设置表格无效。
ng-change