jQuery Validation errorPlacement

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-04-23T14:03:36Z Indexed on 2010/04/24 0:53 UTC
Read the original article Hit count: 447

Filed under:
|

This works:

$("[id$='_zzz']").rules(
    "add",
    {
        required: true,
        minlength: 8,
        messages: {
            required: "...",
            minlength: jQuery.format("...")
        }            
    }
);

The error message comes up.

When I try to style the message, this doesn't work:

$("[id$='_zzz']").rules(
    "add",
    {
        required: true,
        minlength: 8,
        messages: {
            required: "...",
            minlength: jQuery.format("...")
        },
        errorElement: "span",
        errorPlacement: function(error, element) {
            error.insertAfter(element);
            error.css("margin", "0 0 0 5px");
        }             
    }
);

When I style via the validate function, the styling is applied so it works:

$('#aspnetForm').validate({
    errorElement: "span",
    errorPlacement: function(error, element) {
        error.insertAfter(element);
        error.css("margin", "0 0 0 5px");
    }
});

Why can't I style using errorplacement in the rules add function?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about validation