在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
当前回答
有很多方法可以解决这个问题
添加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代码禁用它取决于你的场景。
其他回答
如果隐藏具有必填属性的输入元素,就会发生这种情况。
不使用display:none,你可以使用不透明度:0;
我还必须使用一些CSS规则(如position:absolute)来完美地定位我的元素。
在表单中添加novalidate属性将有助于:
<form name="myform" novalidate>
在我的情况下,问题是输入类型="radio"需要隐藏:
可见性:隐藏;
此错误消息还将显示所需的输入类型单选或复选框是否有显示:none;CSS属性。
如果你想创建自定义的单选/复选框输入,它们必须从UI中隐藏,并且仍然保持所需的属性,你应该使用:
透明度:0;CSS属性
使用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
这发生在我身上,因为我正在使用Materialize JS/CSS框架。当我在物化表单中创建<select>字段时,它被转换为具有许多风格化字段的托管字段,而真正的<select>字段被框架隐藏,仅用于向post请求传递所选值。
因此,它将始终显示控制台错误,除非我使用浏览器默认类使<select>字段的Materialize管理无效。
另一种方法是使用一个带有type="button"而不是type="submit"的按钮,并使用$('form').submit()来发送表单,但您将失去浏览器验证UI,必须开发自己的UI,或者使用框架的UI。