mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user