Split up email branding form into separate pages

We were showing the form to request email branding with a button which
submits your choice immediately. Now, we only submit the form
immediately if "Something else" is the only branding option available to
you. If you select any other radio button (or select "Something else"
when it's not the only option) we take you to another page which either
contains more information or a textbox to fill in the details for the
branding you want.

There is currently some duplication between the new pages and their
tests, but these will be changed in future versions of the work so will
start to differ more.
This commit is contained in:
Katie Smith
2022-01-28 09:45:59 +00:00
parent d45265fcce
commit 92f76638c8
10 changed files with 708 additions and 96 deletions

View File

@@ -2130,6 +2130,7 @@ class BrandingOptions(StripWhitespaceForm):
def __init__(self, service, *args, branding_type="email", **kwargs):
super().__init__(*args, **kwargs)
self.branding_type = branding_type
self.options.choices = tuple(self.get_available_choices(service, branding_type))
self.options.label.text = 'Choose your new {} branding'.format(branding_type)
if self.something_else_is_only_option:
@@ -2194,16 +2195,24 @@ class BrandingOptions(StripWhitespaceForm):
return self.options.choices == (self.FALLBACK_OPTION,)
def validate_something_else(self, field):
if (
self.something_else_is_only_option
or self.options.data == self.FALLBACK_OPTION_VALUE
) and not field.data:
raise ValidationError('Cannot be empty')
if self.branding_type == 'email':
if self.something_else_is_only_option and not field.data:
raise ValidationError('Cannot be empty')
elif self.branding_type == 'letter':
if (
self.something_else_is_only_option
or self.options.data == self.FALLBACK_OPTION_VALUE
) and not field.data:
raise ValidationError('Cannot be empty')
if self.options.data != self.FALLBACK_OPTION_VALUE:
field.data = ''
class SomethingElseBrandingForm(StripWhitespaceForm):
something_else = TextAreaField('', validators=[DataRequired('Cannot be empty')])
class ServiceDataRetentionForm(StripWhitespaceForm):
notification_type = GovukRadiosField(