本文介绍了jQuery验证-require_from_group的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery Validate Framework中的 require_from_group ,并且试图在属于该组的每个字段中显示错误消息,但仅在其中两个字段中显示该错误消息.

I'm using require_from_group from Jquery Validate Framework and I'm trying to display the error message in every single field that belongs to the group, but it is only being displayed in two of them.

HTML代码:

<form id="myform">
<label for="mobile_phone">Mobile phone: </label>
<input class="phoneUS contactMethod" id="mobile_phone" name="mobile_phone">
<br/>
<label for="home_phone">Home phone: </label>
<input class="phoneUS contactMethod" id="home_phone" name="home_phone">
<br/>
<label for="work_phone">Work phone: </label>
<input class="phoneUS contactMethod" id="Work_phone" name="work_phone">
<br/>
<label for="work_phone">Fax phone: </label>
<input class="phoneUS contactMethod" id="fax_phone" name="fax_phone">
<br/>
<label for="work_phone">Email: </label>
<input class="phoneUS contactMethod" id="email" name="email">
<br/>
<input type="submit" value="Go!">
</form>

JS:

$.validator.addClassRules("contactMethod", {
require_from_group: [1, ".contactMethod"]
});

$( "#myform" ).validate();

这是我的JSFiddle: http://jsfiddle.net/3jahT/

This is my JSFiddle:http://jsfiddle.net/3jahT/

我希望每当用户单击提交"时,该消息就会出现在所有字段中,以及当用户取消对其中一个的关注而没有填写时. (jQuery的默认功能).

I want that, whenever user clicks on submit, message appears across all fields, as well as when user unfocus one of them without filling it. (Jquery default functionality).

推荐答案

引用OP:

这是该插件的已知和报告的错误(v1.11.1和之前版本),应该在下一版本(v1.12)中进行修复.

It's a known and reported bug with the plugin (v1.11.1 and prior) that is supposed to be fixed in the next release (v1.12).

在等待下一个版本时,您可以从最新版本下载并构建版本1.12 可以在Github上找到文件.

While waiting for next release, you could download and construct version 1.12 from the latest files available at Github.

否则,您可以比较最新文件中的代码,并将仅适用的更改应用于您的本地插件版本.该功能只能用作临时插件,因为您有意在发布最新版本时将其覆盖.

Otherwise, you could compare the code from the latest files and apply only the applicable changes to your local version of the plugin. This would only serve as a temporary plugin as you would intentionally over-write it with the latest version when it's released.

这篇关于jQuery验证-require_from_group的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 08:47