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

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

问题描述

name='additional_here_about_other_field' 的无效表单控件不可聚焦.此代码用于具有四个下拉列表的选择字段.需要几个选项:#additional_here_about_other_field#additional_who_is_your_orthodontist_field.选择必填字段后,您必须在将显示/取消隐藏的另一个文本字段中输入其他数据.当您选择一个必需的选项,然后切换到一个需要或不需要的选项并尝试提交表单时,您会收到无法聚焦的错误.好像当你选择了一个必填字段然后切换到另一个字段时,之前的必填字段虽然现在隐藏了仍然等待验证?

An invalid form control with name='additional_here_about_other_field' is not focusable. This code is for a select field with four dropdowns. A couple of the options are to be required: #additional_here_about_other_field and the #additional_who_is_your_orthodontist_field. When a required field is selected, you have to enter additional data in another text field that will show/unhide. When you select a required option and then switch to an option which is required or not and try to submit the form, you get the is not focusable error. It seems when you select a required field and then switch to another field, the previous required field although now hidden is still waiting to be validated?

jQuery(document).ready(function () {
	
	if(jQuery("#additional_here_about_other_field").length > 0){
		jQuery("#additional_here_about_other_field").hide();
		jQuery("#additional_how_did_u_hear_about_harp").change(function(){
			if(jQuery(this).val() == 'Other (please specify)'){ jQuery("#additional_here_about_other_field").show().prop('required',true); }
			else { jQuery("#additional_here_about_other_field").hide(); }
		});
	}
	if(jQuery("#additional_who_is_your_orthodontist").length > 0){
		jQuery("#additional_who_is_your_orthodontist").hide();
		jQuery("#additional_how_did_u_hear_about_harp").change(function(){
			if(jQuery(this).val() == 'Orthodontist Referral'){ jQuery("#additional_who_is_your_orthodontist").show().prop('required',true); }
			else { jQuery("#additional_who_is_your_orthodontist").hide(); }
		});
	}
});

HTML snippet

<select name="additional_how_did_u_hear_about_harp" id="additional_how_did_u_hear_about_harp" class="select " data-allow_clear="true" data-placeholder="How Did You Hear About The Harp?" >
	<option value=""  selected='selected'></option>
	<option value="Patient" >Patient</option>
	<option value="Orthodontist Referral" >Orthodontist Referral</option>
	<option value="Trade Show" >Trade Show</option>
	<option value="Mailer" >Mailer</option>
	<option value="Other (please specify)" >Other (please specify)</option>
</select>

<div class="clear"></div>
<p>		
	<input type="text" class="input-text " name="additional_here_about_other_field" id="additional_here_about_other_field" placeholder="Other (please specify)"   value=""  />
</p>
<div class="clear"></div>
<p>		
	<input type="text" class="input-text " name="additional_who_is_your_orthodontist" id="additional_who_is_your_orthodontist" placeholder="Who is your orthodontist?"   value=""  />
</p>
<div class="clear"></div>

推荐答案

隐藏表单控件并不意味着不需要它.并且由于它是必需的,但隐藏了浏览器无法聚焦表单控件.

Just because a form control is hidden doesn't mean it isn't required. And since it is required, but hidden the browser can't focus the form control.

您拥有 .hide() 的每个地方都将其更改为 .hide().prop('required',false) 以解决您的问题.

Every place you have .hide() change it to .hide().prop('required',false) to fix your problem.

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

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