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 ?

1

2 Answers 2

4

Use ngRequired instead, like:

ng-required="checkCountry()"

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

Sign up to request clarification or add additional context in comments.

3 Comments

what should the checkCountry() function return ? a bool ?
@Yasser, yes, I'm on the fiddle, but yes, just like that.
Thanks got a solution from your answer.
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" />

Comments

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.