使用form.submit验证复选框部分

时间:2015-11-28 10:42:02

标签: javascript angularjs forms checkbox

我有一个名称传递给控制器​​的表单,当表单是$ 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')
    }
}

1 个答案:

答案 0 :(得分:0)

我在每个复选框上添加了class CollectionSerializer(serializers.ModelSerializer): class Meta: model = Collection fields = ('id','title', 'nlikes') 表达式。如果没有选中复选框,表达式将设置表格无效。

ng-change