0

Hi I am developing web application in angularjs. I have using multi select dropdown. If user selects anyone option from dropodwn then dont want to fire validation rules.

Below code i am using in html.

 <div class="inputblock" ng-class="{ 'has-error' : ((form2.$submitted && form2.location.$invalid)  || (form2.location.$invalid && form2.location.$dirty))}">
    <div>
        <span class="ang-error" style="color:#fff" ng-show="form2.location.$dirty">Select Location</span>
    </div>
    <div class="selected-items-box"> --- Nationality ---
    <span class="dropdown-icon"></span>
    </div>
        <div class="list">
            <ul class="items-list">
               <li ng-repeat="c in locations">
                   <input type="checkbox" ng-model="selectedCar" name="location" required />
                   <span>{{c.Location}}</span>
               </li>
            </ul>
         </div>
   </div>

Below issue i am facing. Whenever user selects any one option then i do not want to fire validation. But if i did not check all option validation rules are firing

I selected first option i can see below rules in html.

<input type="checkbox" ng-model="selectedCar" name="location" required="" class="ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched">

I have not selected second option and i can see below code in html.

<input type="checkbox" ng-model="selectedCar" name="location" required="" class="ng-pristine ng-untouched ng-invalid ng-invalid-required">

I do not want to fire validation if user selects any one of the option. May i know how to do this? Any help would be greatly appreciated. Thank you.

8
  • for multi select you have to maintain a list instead of single variable. here is really a good answer stackoverflow.com/questions/14514461/… Commented Aug 16, 2017 at 5:48
  • Thank you. I am also using list. How to validate if any one of the value is selected? Commented Aug 16, 2017 at 6:19
  • remove required="" since it makes all fields required,then validate with formname.$valid in angularjs Commented Aug 16, 2017 at 6:24
  • Thank you. i removed required. How to validate with formname.$valid in the above context? Commented Aug 16, 2017 at 6:25
  • you can use myForm.inputName.$setValidity('required', false); Commented Aug 16, 2017 at 6:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.