I am working on a dynamic form using angular.js. Entry field
<div ng-show="condition()"> <input type="text" name="field" required> </div>
If condition () returns false, the input field will not be displayed. But by clicking the submit button, I will get chrome, the message:
An invalid form control with name='field' is not focusable.
Well, the solution is to use ng-required:
<div ng-show="condition()"> <input type="text" name="field" ng-required="condition()"> </div>
Well, here I have to repeat the code using condition () several times.
This gets bad when you can encapsulate ng-show's:
<div ng-show="condition1()"> <div ng-show="condition2()"> <input type="text" name="field" ng-required="condition1() && condition2()"> </div> </div>
Is there a better way, the required tag should be there when the input is visible, and not if it is hidden.
angularjs ng-show
Artisan72
source share