我有一个动态填充的复选框控件。该组中有 3 个复选框。当用户单击提交按钮时,我正在尝试检查是否至少选择了一个复选框。我已经尝试了下面的代码,但我没有收到错误,并且页面正在保存。下面是用户界面代码
<input type="checkbox" id="{{method.id}}" value="{{method.value}}"
name="deliveryMethod[]" ng-model="method.selected"
ng-click="toggleSelection(method.value)"
ng-required="value.length==0"> {{method.value}}
在 js 文件中,我尝试如下:
jQuery("#createForm").bootstrapValidator({
framework: 'bootstrap',
excluded: [':disabled', ':hidden', ':not(:visible)'],
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
TypeSelect: {
validators: {
callback: {
message: 'Please select the type',
callback: function (value, validator, $field) {
var options = validator.getFieldElements('testTypeSelect').val();
return (options != null && options.length >= 1);
}
}
}
},
testName: {
validators: {
notEmpty: {
message: 'name required.'
}
}
},
"deliveryMethod[]": {
validators: {
required: true,
minlength: 1,
maxlength: 3,
message: 'Delivery Type is Mandatory.'
}
},
}
如果不显示消息,则选中如何制作至少一个复选框。谢谢