From 6a6b3f78b140dc34ec01394d7f63f1b81497da89 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 27 Feb 2019 15:10:34 +0000 Subject: [PATCH] Revise error message for non-numeric responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Things we talked about: • asking users to write the number 'as numerals' or 'using digits' isn't very plain English • the style guide says to use an example in the error `..., like 5,000` but not if you have an example in the hint text, so we can't do that • I have reservations about 'correct format', because it sounds odd if you're not describing something like a phone number, NI number or credit card number. Looking back through Request to Go Live tickets on Zendesk. --- I got to September before I found anything that would count as invalid under our new rules: > Possibly around 1,000,000- not planning on implementing emails yet but might change I'll keep looking, but if most people enter the number according to the hint example we might be able to go with a much simpler error just prompting them to enter a number – no convoluted descriptions of what we mean by a number There seemed to be more problems when the Qs were about start volume and peak volume. Users felt the need to explain their plans more. Using 'number' instead of 'volume' is more explicit too – so that probably helps. In terms of errors: `Enter the number of emails you expect to send` `Enter the number of text messages you expect to send` `Enter the number of letters you expect to send` – will probably do it, right? --- app/main/forms.py | 17 +++++++++++++++-- tests/app/main/views/test_service_settings.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index 9068b09e0..bd513ba73 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -178,8 +178,15 @@ class ForgivingIntegerField(StringField): # Actual value is 2147483647 but this is a scary looking arbitrary number POSTGRES_MAX_INT = 2000000000 - def __init__(self, label=None, things='items', **kwargs): + def __init__( + self, + label=None, + things='items', + format_error_suffix='', + **kwargs + ): self.things = things + self.format_error_suffix = format_error_suffix super().__init__(label, **kwargs) def process_formdata(self, valuelist): @@ -209,7 +216,10 @@ class ForgivingIntegerField(StringField): self.POSTGRES_MAX_INT, ) except ValueError: - error = 'Number of {} must be in the correct format'.format(self.things) + error = 'Enter the number of {} {}'.format( + self.things, + self.format_error_suffix, + ) if error: raise ValidationError(error) @@ -658,14 +668,17 @@ class EstimateUsageForm(StripWhitespaceForm): volume_email = ForgivingIntegerField( 'How many emails do you expect to send in the next year?', things='emails', + format_error_suffix='you expect to send', ) volume_sms = ForgivingIntegerField( 'How many text messages do you expect to send in the next year?', things='text messages', + format_error_suffix='you expect to send', ) volume_letter = ForgivingIntegerField( 'How many letters do you expect to send in the next year?', things='letters', + format_error_suffix='you expect to send', ) consent_to_research = RadioField( 'Can we contact you when we’re doing user research?', diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 3e63b3f46..2e85005aa 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1000,7 +1000,7 @@ def test_should_not_default_to_zero_if_some_fields_dont_validate( ) == ( 'How many letters do you expect to send in the next year? ' 'For example, 50,000 ' - 'Number of letters must be in the correct format' + 'Enter the number of letters you expect to send' ) assert mock_update_service.called is False