Let's say I have a custom AddMethod to jQuery Validate like:
$.validator.addMethod('min-length', function (val, element) {
// do stuff
// the error message here needs to be dynamic
}, 'The field cannot be less than than '
+ element.attr('data-min') + // it is within the closure, but it can't grab it
' length.');
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?
addMethodcan take a function as the 3rd (i.e.message) param. See what happens when you pass a function, and inside itconsole.log(this). There's a good chance thatthiswill be the element you're interested in. Or, maybe element is passed in as a param, just like it is for the other function you have.