1

I'm having difficulty getting error placement to work. I have a series of forms on my page, each using the built-in validation classes—required, number, etc—but for some reason the error placement isn't working. At all.

The rest of the form validation works great, but I'm not getting my alert to show.

$(".bundle-forms-form-container form").validate({
    errorPlacement: function(error, element) {
        alert("X");
        var customTarget = $(element).closest("form").find(".errorHere");
        if (true || customTarget.length)
            customTarget.html(error);
        //else
            error.insertAfter(element);
    }
});

1 Answer 1

2

It looks like the problem is that jQuery validate loses its mind if you call validate on a result set with multiple forms. The solution is simple

$(".bundle-forms-form-container form").each(function(i, el){
    $(el).validate({
        errorPlacement: function(error, element) {
            var customTarget = $(element).closest("form").find(".errorHere");
            if (customTarget.length)
                customTarget.empty().append(error);
            else
                error.insertAfter(element);
        }
    });
});
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.