The sum of what the groups option does is to report only one error message for all things within the group. In this example, if you did not group fname and lname , and both of them were necessary, then you would receive two error messages. With a group you get only one. Both elements of the group are still required.
It sounds like you get it right, but it's hard to say why you are not getting this example to work. Using this HTML:
<form id="myform"> First Name: <input type="text" name="fname" id="fname"/><br> Last Name: <input type="text" name="lname" id="lname"/><br> <input type="submit"/> </form>β
And this confirmation code:
$("#myform").validate({ rules: { fname: { required: true }, lname: { required: true } }, groups: { username: "fname lname" }, errorPlacement: function(error, element) { if (element.attr("name") == "fname" || element.attr("name") == "lname" ) error.insertAfter("#lname"); else error.insertAfter(element); } })β
I'm fine: http://jsfiddle.net/ryleyb/cbJj6/
A more sophisticated example that I helped someone is here: Using the jQuery validation plugin to check if one or more of the checkboxes (with different names) is selected The checkbox was checked, and only one message was requested if it werenβt.
source share