Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An invalid form control with name='' is not focusable on hidden element

Tags:

angularjs

I have an element that conditionally appears that is required to be filled out when visible. (using ng-required)

However, when it is not visible, I'm getting the following error:

An invalid form control with name='' is not focusable

How do I force ng-required to work ONLY if it element is visible. I do not want to enter novalidate in the form, because if I do, when the element is visible, the validation does not occur.

like image 623
KingKongFrog Avatar asked Mar 12 '15 21:03

KingKongFrog


2 Answers

Like this, using a boolean for both ng-show and ng-required:

<form>
  <input type="text" ng-show="displayCondition" ng-required="displayCondition"/>
</form>

Good question - a lot of people do not realize that passing false into ng-required disables the directive.

like image 182
Andrew Templeton Avatar answered Nov 12 '22 01:11

Andrew Templeton


I solved it very easy with using ng-if instead of ng-show! Us only ng-if. When it is not visible the element is not in the code anymore. So the browser will not validate it.

like image 35
elpeyotl Avatar answered Nov 12 '22 03:11

elpeyotl