Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top