Fix email branding request page with only textbox

If there aren’t a range of options (normally presented as radio buttons)
to show the user on the email branding request page then we just show
the textbox. But we were still doing form validation on the radio
buttons, even though the user couldn’t see them to click them. This
stopped the user from being able to submit the form.

This commit fixes the problem by, in this specific case, pre-ticking the
‘Something else’ radio button.
This commit is contained in:
Chris Hill-Scott
2019-10-09 16:42:30 +01:00
parent 94f0084b94
commit 7f033efc28
2 changed files with 35 additions and 2 deletions

View File

@@ -1368,8 +1368,8 @@ class BrandingOptionsEmail(StripWhitespaceForm):
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())
if self.something_else_is_only_option:
self.options.data = self.FALLBACK_OPTION_VALUE
@staticmethod
def get_available_choices(service):