R
R
realgord882015-07-23 16:57:01
Flask
realgord88, 2015-07-23 16:57:01

How to translate wtforms tooltips?

How to translate tooltips that pop up when the input format is incorrect in the form?584971b75b234f86a4702dd298d3803f.png

from flask.ext.wtf import Form
from wtforms import TextField
from wtforms.validators import Required
from wtforms import validators
from wtforms.fields.html5 import EmailField

class RegisterForm(Form):
    Nickname = TextField('Nickname', validators = [Required()])
    Email = EmailField('Email address', [validators.DataRequired(), validators.Email()])
    Password = TextField('Password', validators = [Required()])
    RePassword = TextField('Password', validators = [Required()])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shvedov, 2015-07-23
@realgord88

These are browser tooltips, depending on the specific system. They appear when validation attributes (required, pattern ...) are set on the fields. If you want to change - do not specify attributes, check it yourself and draw tooltips the way you want.

V
Vladimir Abiduev, 2015-07-24
@gunlinux

Certainly not babel, but a solution. And the validation crashes on html5 validation. Which is not yet available in all browsers.

REQ_TEXT = u'Заполните это поле'

class RegistrationForm(Form):
    Nickname = TextField('Nickname', validators = [Required(REQ_TEXT)])
    Password = TextField('Password', validators = [Required(u'Укажите пароль')])

    email = StringField(u'Электронная почта',
                        validators=[Required(REQ_TEXT),
                                    Length(1, 64),
                                    Email(REQ_TEXT)])

    def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError(u'Почта уже занята')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question