在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
在谷歌Chrome一些客户无法继续到我的支付页面。 当我试图提交一个表单时,我得到这个错误:
name= "无效的窗体控件不可聚焦。
这来自JavaScript控制台。
我读到这个问题可能是由于隐藏字段具有必需的属性。 现在的问题是,我们使用的是。net webforms required字段验证器,而不是html5 required属性。
谁得到这个错误似乎是随机的。 有谁知道解决办法吗?
当前回答
当你向输入字段提供style="display: none;"和required属性时,这个问题就会发生,并且在提交时会进行验证。 例如:
<input type="text" name="name" id="name" style="display: none;" required>
这个问题可以通过从HTML的输入字段中删除所需的属性来解决。如果需要添加所需属性,请动态添加。如果你正在使用JQuery,请使用下面的代码:
$("input").prop('required',true);
如果需要动态删除该字段,
$("input").prop('required',false);
如果你不使用JQuery,你也可以使用纯Javascript:
document.getElementById('element_id').removeAttribute('required');
其他回答
我也是带着同样的问题来的。对我来说(在需要的时候注入隐藏元素——比如在工作应用程序中接受教育)有必要的标志。
我意识到,验证器对注入文件的启动速度比文档准备好还要快,因此它会报错。
我最初的ng-required标记使用可见性标记(vm.flags.hasHighSchool)。
我通过创建一个专用标志来设置required来解决这个问题 ng-required = " vm.flags。highSchoolRequired == true"
我添加了一个10ms的回调设置标志,问题解决了。
vm.hasHighSchool = function (attended) {
vm.flags.hasHighSchool = attended;
applicationSvc.hasHighSchool(attended, vm.application);
setTimeout(function () {
vm.flags.highSchoolRequired = true;;
}, 10);
}
Html:
<input type="text" name="vm.application.highSchool.name" data-ng-model="vm.application.highSchool.name" class="form-control" placeholder="Name *" ng-required="vm.flags.highSchoolRequired == true" /></div>
这个问题发生在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">。
我在使用Angular JS时也发现了同样的问题。这是由于与ng-hide一起使用required引起的。当我点击提交按钮,而这个元素是隐藏的,然后发生错误,无效的窗体控件与名称= "是不可聚焦的。终于!
例如,将ng-hide和required一起使用:
<input type="text" ng-hide="for some condition" required something >
我通过用ng-pattern代替所需的来解决它。
例如解决方案:
<input type="text" ng-hide="for some condition" ng-pattern="some thing" >
对我来说,问题是在div中输入类型电子邮件的可见性:隐藏,类似这样的东西
<form>
<div style="visibility: hidden;">
<input type="email" name="email" id="email">
............
</form>
然后你可以改变type="email"为type="text"或删除可见性:隐藏;
我希望在这个冗长的答案种子中没有遗漏我的场景是一些非常奇怪的事情。
我有div元素,动态更新通过对话框被调用在他们加载和得到行动。
简而言之,div id有
<div id="name${instance.username}"/>
我有一个用户:测试帐户,出于某种原因,编码在java脚本世界中做了一些奇怪的事情。我收到了在其他地方工作的表单的错误消息。
缩小到这个范围,重新测试使用数字代替,即id似乎解决了这个问题。