Jquery Validate - require_from_group

戏子无情 提交于 2020-01-17 03:04:26

问题


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 code:

<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();

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

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).


回答1:


Quote OP:

"I'm using require_from_group from jQuery Validate... 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."

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).

"I want that, whenever user clicks on submit, message appears across all fields..."

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.



来源:https://stackoverflow.com/questions/22674611/jquery-validate-require-from-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!