I have an Angular validation script where the field must be valid if it is not disabled, in which case it should be ignored.
(I use ng-messages for demo purposes, this does not affect the state of $errors form / field).
How do we clear max and required errors when a field is disabled?
<form name="myForm"> <label><input type="checkbox" ng-model="disable"> disable field</label><br> <input name="width" type="number" ng-disabled="disable" ng-disabled="disable" ng-model="someValue" max="100" required> <div class="errors" ng-messages="myForm.width.$error"> <div ng-message="required">Please enter a width</div> <div ng-message="max">Width is over the max permitted</div> </div> </form>
myForm. $ valid = {{myForm. $ valid}}
Here is an example of working with JS Bin: http://jsbin.com/supapotoci/1/edit?html,output
source share