mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-17 04:59:37 -04:00
Allow elaboration when ‘something else’ is chosen
Letting people input a bit of free text should reduce the amount of back and forth we have to do over support tickets when setting up someone’s branding. If something else is the only option then we don’t show the radio button at all and have just the free text input on the page (not behind a progressive disclosure).
This commit is contained in:
@@ -1359,16 +1359,17 @@ class LinkOrganisationsForm(StripWhitespaceForm):
|
||||
|
||||
class BrandingOptionsEmail(StripWhitespaceForm):
|
||||
|
||||
options = RadioField(
|
||||
'Choose your new email branding',
|
||||
validators=[
|
||||
DataRequired()
|
||||
],
|
||||
)
|
||||
FALLBACK_OPTION_VALUE = 'something_else'
|
||||
FALLBACK_OPTION = (FALLBACK_OPTION_VALUE, 'Something else')
|
||||
|
||||
options = RadioField('Choose your new email branding')
|
||||
something_else = TextAreaField('Describe the branding you want')
|
||||
|
||||
def __init__(self, service, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.options.choices = tuple(self.get_available_choices(service))
|
||||
if not self.something_else_is_only_option:
|
||||
self.options.validators.append(DataRequired())
|
||||
|
||||
@staticmethod
|
||||
def get_available_choices(service):
|
||||
@@ -1404,7 +1405,21 @@ class BrandingOptionsEmail(StripWhitespaceForm):
|
||||
):
|
||||
yield ('organisation', service.organisation.name)
|
||||
|
||||
yield ('something_else', 'Something else')
|
||||
yield BrandingOptionsEmail.FALLBACK_OPTION
|
||||
|
||||
@property
|
||||
def something_else_is_only_option(self):
|
||||
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('Can’t be empty')
|
||||
|
||||
if self.options.data != self.FALLBACK_OPTION_VALUE:
|
||||
field.data = ''
|
||||
|
||||
|
||||
class ServiceDataRetentionForm(StripWhitespaceForm):
|
||||
|
||||
Reference in New Issue
Block a user