4

I have a form as shown below, I have kept only 1 field here for simplicity. In my form I have many other fields including a country dropdown. If country selected is A,B or C I want to remove the required validation which I do using a addressRequired which gets a true/false value on change of country.

I am removing the required using .removeAttr() and it does get remove from the html.

But the ng-disabled="myAbcForm.$invalid" stills shows invalid.

<form name="myAbcForm" ng-submit="submitForm(myAbcForm.$valid)" novalidate class="myAbcForm">
   <div class="element-box fltlt">
        <label>Address </label><sup ng-show="addressRequired">*</sup>
        <input type="text" value="" ng-model="details.Address" required="">
        <span ng-show="!details.Address && addressRequired" class="error-msg field-validation-error">Address is required.</span>
    </div>
    <div id="clearfix">
        <input type="submit" value="Update" class="btn fltlt btnBG" ng-disabled="myAbcForm.$invalid" />
    </div>
</form>

Any suggestions ?

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • For more information check this: [http://stackoverflow.com/questions/16648669/what-is-the-difference-between-required-and-ng-required][1] [1]: http://stackoverflow.com/questions/16648669/what-is-the-difference-between-required-and-ng-required – Durgesh Nov 06 '14 at 08:35

2 Answers2

4

Use ngRequired instead, like:

ng-required="checkCountry()"

http://jsfiddle.net/coma/0jz49knd/1/

coma
  • 16,429
  • 4
  • 51
  • 76
1

With a little hint from coma's answer

Here is what I am using now

<input type="text" value="" 
  ng-model="details.Address" 
  ng-required="addressRequired" />
Community
  • 1
  • 1
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281