Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom validators not working #853

Open
MPanek6 opened this issue Oct 2, 2024 · 0 comments
Open

Custom validators not working #853

MPanek6 opened this issue Oct 2, 2024 · 0 comments

Comments

@MPanek6
Copy link

MPanek6 commented Oct 2, 2024

Custom validators don't seem to fire. I've followed the documentation on the wiki as well as tried various online solutions

from wtforms import Form, StringField
from wtforms.validators import ValidationError

class xyzForm(Form):
    name = StringField("name")

    def validate_name(form, field):    # Using (self, field) or (self, form, field) also doesn't work
        print('fired')
        if len(field.data) > 2:
            raise ValidationError('blahblah')

Similarly, the following also doesn't work

from wtforms import Form, StringField
from wtforms.validators import ValidationError

def custom_val(form, field): 
    print('fired')
    if len(field.data) > 2:
        raise ValidationError('blahblah')

class xyzForm(Form):
    name = StringField("name", validators=[custom_val])

Environment

  • Python version: 3.9.18
  • wtforms version: 3.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant