Skip to content
Advertisement

Dynamic jQuery Validate error messages with AddMethod based on the element

Let’s say I have a custom AddMethod to jQuery Validate like:

JavaScript

I can’t figure out a way to get the element variable in question, and get any values from it. What am I missing here?

Advertisement

Answer

From looking at the validator source code, I think this should do it:

JavaScript

In your original code, the message string is NOT within the closure; the closure is the 2nd argument of addMethod, and the error message is the 3rd argument.

Advertisement