在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:

name= "无效的窗体控件不可聚焦。

这来自JavaScript控制台。

我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。

谁得到这个错误似乎是随机的。 有谁知道解决办法吗?


当前回答

在我的情况下,问题是输入类型="radio"需要隐藏:

可见性:隐藏;

此错误消息还将显示所需的输入类型单选或复选框是否有显示:none;CSS属性。

如果你想创建自定义的单选/复选框输入,它们必须从UI中隐藏,并且仍然保持所需的属性,你应该使用:

透明度:0;CSS属性

其他回答

我来说明一下我的情况,因为它不同于上面所有的解。我有一个html标签没有正确关闭。元素不是必需的,但它嵌入在一个隐藏的div中

在我的案例中,问题在于type="datetime-local",出于某种原因,它在表单提交时被验证。

我改变了这个

<input type="datetime-local" />

<input type="text" />

在表单中添加novalidate属性将有助于:

<form name="myform" novalidate>

对于其他AngularJS 1。x个用户在那里,这个错误出现是因为我隐藏了一个窗体控件显示,而不是完全从DOM中删除它时,我不需要控件完成。

我通过在包含需要验证的表单控件的div上使用ng-if而不是ng-show/ng-hide来修复这个问题。

希望这能帮助到你的边缘情况用户。

这个问题发生在Chrome上,如果一个表单字段验证失败,但由于各自的无效控件无法聚焦,浏览器试图显示消息“请填写此字段”旁边也失败了。

由于多种原因,表单控件在触发验证时可能无法聚焦。下面描述的两种情况是最突出的原因:

The field is irrelevant according to the current context of the business logic. In such a scenario, the respective control should be disabled or removed from the DOM or not be marked with the required attribute at that point. Premature validation may occur due to a user pressing ENTER key on an input. Or a user clicking on a button/input control in the form which has not defined the type attribute of the control correctly. If the type attribute of a button is not set to button, Chrome (or any other browser for that matter) performs a validation each time the button is clicked because submit is the default value of a button's type attribute.

为了解决这个问题,如果你的页面上有一个按钮是做其他事情而不是提交或重置,请记住这样做:<button type="button">。

奇怪的是,每个人都建议删除验证,而验证的存在是有原因的…… 不管怎样,如果你在使用一个自定义控件,并且想要维护验证,你可以这样做:

第一步。从输入中删除无显示,因此输入变得可聚焦

.input[required], .textarea[required] {
    display: inline-block !important;
    height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    z-index: -1 !important;
    position: absolute !important;
}

第二步骤。如果样式不够,则在特定情况下的输入上添加无效事件处理程序

inputEl.addEventListener('invalid', function(e){
   //if it's valid, cancel the event
   if(e.target.value) {
       e.preventDefault();
   }
});