名称=''的无效表单控件不可聚焦 [英] An invalid form control with name='' is not focusable

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

问题描述

我的网站存在一个严重问题。
在谷歌浏览器中,有些客户无法进入我的付款页面。
当试图提交表单时,出现以下错误:

 名称=''的无效表单控件不是可获得焦点。 

这是来自JavaScript控制台。



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



似乎是随机出现此错误的人。
是否有人知道这个解决方案?

解决方案

这是不够的状态


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

不解释问题,OP可能不知道为什么它会有帮助,或者它确实有帮助。

这里是一个真正解释案例的答案,理解问题应该使您得出适合您开发的解决方案:


Chrome想要专注于需要但仍然为空的控件,以便弹出消息请填写此字段。但是,如果控件隐藏在Chrome想要弹出消息的时候,即在提交表单时,Chrome无法关注控件,因为它是隐藏的,因此表单不会提交。



所以,为了解决这个问题,当一个控件被javascript隐藏时,我们也必须从该控件中移除'required'属性。


为了充分利用警告,请考虑这一点 - 验证失败时不要隐藏字段。但这不是一个严格的规定,也不是一个规则。正如我在下面的评论中提到的那样,我将其解释为


在某些情况下,问题根本不存在,并且不会导致功能在应用程序中。然后错误可能被忽略。



更新:2015年8月21日



有问题的错误也可能由于过早的验证而产生。如果您的<按钮> 输入没有设置 类型 属性,则可能会发生过早验证。如果没有将按钮的type属性设置为按钮,则Chrome(或任何其他浏览器)会在每次单击按钮时执行验证,因为 submit 是默认值按钮类型。要解决这个问题,如果您的网页上有一个按钮,可以执行 提交 重置 ,请记住这样做:< button type =button>


I have an acute problem on my website. In Google Chrome some customers are not able to proceed to my payment page. When trying to submit a form I get this error:

An invalid form control with name='' is not focusable.

This is from the JavaScript console.

I read that the problem could be due to hidden fields having the required attribute. Now the problem is that we are using .net webforms required field validators, and not the html5 required attribute.

It seems random who gets this error. Is there anyone who knows a solution for this?

解决方案

It's not enough to state

Adding a novalidate attribute to the form will help

It does not explain the problem, and the OP may not have understood why it would help, or if it really is helpful.

Here's an answer that truly explains the case, understanding the problem should enable you to arrive at a solution that is suitable for your development:

Chrome wants to focus on a control that is required but still empty so that it can pop up the message 'Please fill out this field'. However, if the control is hidden at the point that Chrome wants to pop up the message, that is at the time of form submission, Chrome can't focus on the control because it is hidden, therefore the form won't submit.

So, to get around the problem, when a control is hidden by javascript, we also must remove the 'required' attribute from that control.

To put the warning into good use, consider this - don't hide a field when it fails validation. But that is not a strict rule, nor is it a rule at all. As I mentioned in my comment below, I paraphrase

In some cases, the issue is not a problem at all and does not cause loss of functionality in an application. Then the error maybe ignored.

UPDATE: August 21, 2015

The error in question may also arise due to a premature validation. Premature validation can occur when you have a <button> input without a set type attribute. Without the type attribute of a button being 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 type of buttons. To solve the problem, if you have a button on your page that does something else other than submit or reset, always remember to do this: <button type="button">

这篇关于名称=''的无效表单控件不可聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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