Checkbox valiadtion using Angular Js

49 views Asked by At

I am using Angular js, in which i have a textbox and collection of checkbox. I want to check if atleast one checkbox is checked when the submit button is clicked. Below is the existing code:

<form name="mainForm" id="createForm" ng-submit="mainForm.$valid && add()" novalidate>
        <div ng-controller="testController" ng-init="init()">    

    <div>
                        <label>Name :</label>
                    </div>
                    <div>
                        <input type="text" maxlength="150" required ng-model="testName" name="testName" />
                    </div>
                </div>
                <span style="color:red" ng-show="submitted == true && mainForm.testName.$error.required">Name is required</span>
                <br />
            <div class="row">
                    <div>
                        <label>Delivery Method</label>
                    </div>
                    <div ng-repeat="method in deliveryMethods">
                        <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}}
                    </div>
                </div>

    <input type="submit" value="Submit" ng-click="submitted=true"/>

How to achieve this in angular js? Thanks

0

There are 0 answers