DEV Community

Discussion on: Combining multiple forms in Flask-WTForms but validating independently

Collapse
 
rozzah profile image
RoZZaH • Edited

While this may be obvious to those more experienced.. if you have a custom validator at the subform/field level you need to define a custom validator outside the block as inline validators (e.g. def validate_somefield) only seem to work on validate_on_submit()

def custom_validator(form,field):
  local_var = field.data
  if some condition:
    raise ValidationError("some error message")

class SomeSubForm(FlaskForm)
    some_field = StringField(validators=[custom_validator])