I have a checkbox control which is dynamically filled. There are 3 checkboxes in the group. I am trying to check if at least one checkbox is selected, when user clicks on submit button. I have tried the below code, but I am not getting the error, and the page is getting saved. Below is the UI code
<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}}
In the js file, i tried as below:
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.'
}
},
}
How to make at least one checkbox is checked, if not show the message. Thanks