insin/newforms — Issue #11: custom validator messages are broken
Author: lautgesetz
Created: 2012-02-13 20:37:37+00:00
State: open

I created a custom validator like this:

var validateUsername = new forms.RegexValidator(/^[a-zA-Z_.-]+$/,
'must contain only letters, numbers, -, _ or .');

However, the custom validation message is not actually applied when the validator generates an error. Instead I get the default "invalid" error message. I can solve this by doing the following in the form constructor:

username: forms.CharField({maxLength: 255, validators: [validateUsername],
errorMessages: { invalid: validateUsername.message } }),

But it seems like this should not be necessary and is probably a bug.