0

I am trying to make use of the errorPlacement option as follows:

 $("#MyForm").validate({
            rules: {
                'brand': {
                    required: true,
                    errorPlacement : function(error, element){
                        console.log(error);
                        console.log(element);
                        error.appendTo(element.parent('div.formRight'));
                        error.css("clear", "both");
                    }
                }

But for some reason the function is only receiving one parameter (the element) ... in the console logs in the error parameter there is the element reference whilst the element parameter is undefined.

Is there a specific way to reference the error element?

Thanks

1 Answer 1

1

To properly use the errorPlacement callback function, it's just another option like rules. In other words, you do not put errorPlacement inside of rules; instead, it's a sibling of rules and is applied globally.

$("#MyForm").validate({
        rules: {
            brand: {
                required: true
            }
        },
        errorPlacement: function(error, element) {
            console.log(error);
            console.log(element);
            error.appendTo(element.parent('div.formRight'));
            error.css("clear", "both");
        },
        // any other options
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.