在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
当前回答
使用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
其他回答
有很多方法可以解决这个问题
添加novalidate到你的表单,但这是完全错误的,因为它将删除表单验证,这将导致用户输入错误的信息。
<表单操作=“....” class=“付款详细信息” 方法=“post” novalidate>
Use可以从必填字段中删除必填属性,这也是错误的,因为它将再次删除表单验证。 而不是这样:
<input class="form-control" id="id_line1" maxlength="255" name="line1" placeholder="第一行地址" type="text" required="required">
Use this:
<input class="form-control" id="id_line1" maxlength="255" name="line1" placeholder="第一行地址" type="text">
当您不打算提交表单而不是执行其他选项时,Use可以禁用必填字段。这是我建议的解决方案。 如:
<input class="form-control" id="id_line1" maxlength="255" name="line1" placeholder="第一行地址" type="text" disabled="disabled">
或者通过javascript / jquery代码禁用它取决于你的场景。
如果你有这样的代码,它会显示这条消息:
<form>
<div style="display: none;">
<input name="test" type="text" required/>
</div>
<input type="submit"/>
</form>
在您的表单输入中。你把需要的保存在隐藏输入中,这就是为什么它抛出:
An invalid form control with name='' is not focusable
检查抛出无效的输入名称,您将其隐藏并保留为必需的。
只需从隐藏的输入名称中删除所需的。完成了。
是的. .如果隐藏表单控件有必填字段,则会显示此错误。一种解决方案是禁用此表单控件。这是因为通常如果你隐藏一个表单控件,那是因为你不关心它的值。所以这个表单控件的名称值对在提交表单时不会被发送。
在我的情况下,问题是输入类型="radio"需要隐藏:
可见性:隐藏;
此错误消息还将显示所需的输入类型单选或复选框是否有显示:none;CSS属性。
如果你想创建自定义的单选/复选框输入,它们必须从UI中隐藏,并且仍然保持所需的属性,你应该使用:
透明度:0;CSS属性