JQuery Validation success: working with groups

JQuery Validation success: working with groups


I've been struggling with how to use the "success" mechanism to show "Ok" when a field is valid.  This works great until i have a group of fields in one line: first_name and last_name.  The approach I was using shows "Ok" at the end of the line when the first field is validated, even though the second one is required too.

What I ended up doing was to handle the "success" event separately for the group  In the validate function options:

      groups: { username: "patient[first_name] patient[last_name]" }, 
      success: function(label) {
            if (label.attr('for') == "username") {
                  if (!($("#patient_first_name").val() == "" || $("#patient_last_name").val() == "") ){
                        label.addClass("valid").text("Ok");
                  }
            } else {
                  label.addClass("valid").text("Ok");
            }
      },

While that works, it was only easy because this is a simple "required" validation.  I'd hate to have to duplicate the logic for email.  I was wondering if that's the expected behaviour for the combination of "success" and "groups".  Perhaps it is the expected behavior, but a tool could be provided in future versions to help the developer avoid re-validating manually?  E.g. the "success" event could send not only a label but also the objects in the group;  or the "valid()" method could check just one field without marking the whole form; or there could be another method similar to valid but only checking one field.

I mention the latter approach because  I tried calling $("patient_first_name").valid(), but that validated the whole form and made last name appear as invalid even though the user just hadn't gotten to that field yet.