Jquery validate - groups and their labels

Good morning

I have been using the jquery validation function for a while, and this is great. However, wondering if it is possible to remove the group error label only after the BOTH (or 3 or 4) elements in the group are correct. For example, if I have an empty first name and last name in a group, the error disappears after entering only the first name. I know I can disable the onfocusout function, but I would prefer. Thank!

+3
source share
1 answer

It really looks like a jQuery validation error (you can write the error here ). To get around this, you can define a very specific rule:

$.validator.addMethod("name", function(value, element) {
    return $("#firstname").val() !== '' && $("#lastname").val() !== '';
}, "Name is required");

And still use the functionality groups:

$("form").validate({
    groups: {
        name: "firstname lastname"
    },
    firstname: "name",
    lastname: "name",
    errorPlacement: function(error, $element) {
        var name = $element.attr("name");
        if (name === "firstname" || name === "lastname") {
            error.insertAfter("#name");
        } else {
            error.insertAfter($element);
        }
    }
});

, id , . .

: http://jsfiddle.net/Rqbws/

+5

All Articles