When using the Unique() validator of wtforms_components (with Flask and SQLAlchemy), the default error message that shows up in the form is "Already exists". How can I change this error message as easy as I can change the error message of the DataRequired() validator?
The error message of the DataRequired() validator can be changed like this:
from wtforms.validators import DataRequired
class SignupForm():
email = EmailField('Email', validators=[DataRequired('THIS IS MY NEW ERROR MESSAGE.')])
This changes the default error message from "This is required." to "THIS IS MY NEW ERROR MESSAGE." I am looking for a similarly simple and elegant solution for changing the default error message of the Unique() validator of wtforms_components
I was hoping that there is something like the following. However, it does not work:
from wtforms_components import Unique
class SignupForm():
email = EmailField('Email', validators=[Unique(User.email, get_session=lambda: db.session, 'THIS IS MY NEW ERROR MESSAGE.')])
The way, the validator is normally works (with the default error message) is as follows:
from wtforms_components import Unique
class SignupForm():
email = EmailField('Email', validators=[Unique(User.email, get_session=lambda: db.session)])
I am using the following packages:
Flask==0.10.1
Flask-SQLAlchemy==2.1
Flask-WTF==0.9.5
WTForms-Components==0.9.7
I did not find a solution in the WTForms-Alchemy documentation (http://wtforms-alchemy.readthedocs.io/en/latest/validators.html). Also, I did not find a solution in the WTForms-Components documentation (http://wtforms-components.readthedocs.io/en/latest/#unique-validator). There was no solution in this forum either.
Thanks a lot for your hints in advance.