Allow free allowance to be set to 0

We want to be able to set the free allowance for a service to 0, but the
form was not allowing this - it gave an error message of `Cannot be
empty`. This can be fixed by changing the WTForms validator from
`DataRequired` (which coerces 0 to falsey) to the `InputRequired`
validator.
This commit is contained in:
Katie Smith
2022-02-25 11:27:56 +00:00
parent 05b8fd7c01
commit 9dc3252079
2 changed files with 10 additions and 2 deletions

View File

@@ -40,7 +40,14 @@ from wtforms import (
ValidationError,
validators,
)
from wtforms.validators import URL, DataRequired, Length, Optional, Regexp
from wtforms.validators import (
URL,
DataRequired,
InputRequired,
Length,
Optional,
Regexp,
)
from app.formatters import format_thousands, guess_name_from_email_address
from app.main.validators import (
@@ -1300,7 +1307,7 @@ class FreeSMSAllowance(StripWhitespaceForm):
free_sms_allowance = GovukIntegerField(
'Numbers of text message fragments per year',
validators=[
DataRequired(message='Cannot be empty')
InputRequired(message='Cannot be empty')
]
)