samedi 28 novembre 2015

Using form.submit to validate checkbox section

I have a form with a name that is passed to the controller, and when the form is $valid I continue to process data. This used to work with radio buttons, but when I switched to checkboxes, the validation passes only when all checkboxes are selected. How can I make it so, selecting 1 makes the form valid? Code snippet for reference:

<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')
    }
}




Aucun commentaire:

Enregistrer un commentaire