名称=''的无效表单控件不能集中在隐藏元素上 [英] An invalid form control with name='' is not focusable on hidden element

查看:65
本文介绍了名称=''的无效表单控件不能集中在隐藏元素上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有条件出现的元素,需要在可见时填写. (使用ng-required)

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

如何强制ng-required仅在可见的情况下起作用.我不想在表单中输入novalidate,因为如果这样做,当元素可见时,不会进行验证.

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.

推荐答案

与此类似,对ng-showng-required都使用布尔值:

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

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

好问题-许多人没有意识到将false传递到ng-required会禁用该指令.

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

这篇关于名称=''的无效表单控件不能集中在隐藏元素上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆