在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
当前回答
不仅仅是在其他答案中提到的必填项。这也是由于将<input>字段放置在隐藏的<div>中导致的,该字段持有无效值。
考虑下面的例子,
<div style="display:none;">
<input type="number" name="some" min="1" max="50" value="0">
</div>
这将抛出相同的错误。所以确保<input>字段隐藏<div>不持有任何无效值。
其他回答
使用ElementInternals API的自定义元素元素不能使用delegatesFocus: true与shadowRoot,因为元素必须直接接收焦点(目前,这可能会发展)在公开的表单的DOM树(父表单可以在shadowRoot,它只是必须在同一部分的树与自定义和其他表单元素);元素必须是可见的,在我的实验中tabindex=0是必需的元素(-1似乎也工作)
一个从googlchrome扩展的带有自定义元素的演示在https://jimmont.github.io/samples/report-validity/
the error is simply reporting that an element which has attributes indicating it needs validation cannot receive focus when there's a problem with the validation, so the user can correct the error; if the error and information is coming in as expected you can ignore the error; otherwise it's likely the result of some UI features hiding elements and a mix of unexpected behavior; it's possible to use another approach in implementations to allow the user to walk back through a flow of some sort, but it appears that's beyond the scope of the question at the moment
就我而言…
Ng-show被利用了。 Ng-if被放到了它的位置,修复了我的错误。
对我来说,问题是在div中输入类型电子邮件的可见性:隐藏,类似这样的东西
<form>
<div style="visibility: hidden;">
<input type="email" name="email" id="email">
............
</form>
然后你可以改变type="email"为type="text"或删除可见性:隐藏;
在你的表单中,你可能有隐藏的输入需要的属性:
<input type="hidden" required /> <input type="file" required style="display: none;"/>
表单不能专注于这些元素,你必须从所有隐藏的输入中删除required,或者在javascript中实现一个验证函数来处理它们,如果你真的需要一个隐藏的输入。
有些事情仍然让我感到惊讶……我有一个具有两个不同实体的动态行为的表单。一个实体需要一些其他实体不需要的字段。 所以,我的JS代码,取决于实体,做一些类似的事情: $ (' # periodo ') .removeAttr(“需要”); $ (" # periodo-container ") hide ();
当用户选择另一个实体时: $ (" # periodo-container "),告诉(); $ (" # periodo”)。道具(“需要”,真正的);
但有时,当提交表单时,会出现问题:“name=periodo的无效表单控件”不可聚焦(我对id和名称使用相同的值)。
要解决这个问题,您必须确保您正在设置或删除'required'的输入始终可见。
所以,我所做的是:
$("#periodo-container").show(); //for making sure it is visible
$('#periodo').removeAttr('required');
$("#periodo-container").hide(); //then hide
这解决了我的问题…难以置信。