Validation Plugin, changing message with addMethod
Hi,
I've written my own custom validation method using addMethod which works great.
But what I'd like to do is change the error message depending on which part of the validation it fails on.
I've tried defining & using a var for the message but the message never changes, a very simple cut-down example:
- var customError = "";
- $.validator.addMethod("myvalidator", function(value, element) {
- var returnVal = true;
-
if (value.length === 0) {
- customError = "cannot be blank";
- returnVal = false;
- }
- if (value.length > 10) {
- customError = "too long.";
- returnVal = false;
- }
- return returnVal;
- }, "Error: " + customError);
The message is always only "Error: "
The value of customError is changing (can be seen in Firebug) but it's never appended to the message.
Is there a way to do this?
Cheers,
Mike