I have defined a form like this:
class RecordForm(Form):
rating = IntegerField('Rating')
If no value is inserted I get a default message like this:
Not a valid integer value
I would like to have a custom message instead, so I came up with this:
class RecordForm(Form):
rating = IntegerField('Rating',[validators.DataRequired("Helllo???")])
The custom message works now, but I get a side effect. 0 (zero) is no longer accepted as an integer value. What are my options here please?
Use InputRequired
instead:
class RecordForm(Form):
rating = IntegerField('Rating',[validators.InputRequired("You got to enter some rating!")])
From the docs:
Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired looks at the post-coercion data.
(Emphasis mine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With