wtforms / flask-wtf

Simple integration of Flask and WTForms, including CSRF, file upload and Recaptcha integration.
https://flask-wtf.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.46k stars 310 forks source link

DataRequired and NumberRange can't handle 0 #587

Open mickkn opened 10 months ago

mickkn commented 10 months ago

0 (zero) value not allowed for DecimalField with NumberRange validator for DataRequired

latitude = DecimalField(
    validators=[DataRequired(), NumberRange(min=-90, max=90)],
    render_kw={
        "placeholder": "Latitude, e.g. 55.9397°",
        "title": "Latitude",
    },
    places=6,
)

The problem seems to be the DataRequired that checks "if field.data" which I assume should be if field.data is not None

Could use InputRequired instead, but for some users, this field is ReadOnly in my application, which means that InputRequired is not validated correctly either.

0 is between -90 and 90

Environment: