Remove unused legends from radio groups

This commit is contained in:
Erin Song 2024-11-21 17:05:08 -08:00
parent f918720383
commit e76571eb50
No known key found for this signature in database
5 changed files with 37 additions and 17 deletions

View file

@ -544,6 +544,7 @@ class OtherContactsYesNoForm(BaseYesNoForm):
"""The yes/no field for the OtherContacts form."""
form_choices = ((True, "Yes, I can name other employees."), (False, "No. (Well ask you to explain why.)"))
title_label = "Are there other employees who can help verify your request?"
field_name = "has_other_contacts"
@property

View file

@ -239,6 +239,10 @@ class BaseYesNoForm(RegistrarForm):
# Default form choice mapping. Default is suitable for most cases.
form_choices = ((True, "Yes"), (False, "No"))
# Option to append question to aria label for screenreader accessibility.
# Not added by default.
aria_label = ""
def __init__(self, *args, **kwargs):
"""Extend the initialization of the form from RegistrarForm __init__"""
super().__init__(*args, **kwargs)
@ -256,7 +260,11 @@ class BaseYesNoForm(RegistrarForm):
coerce=lambda x: x.lower() == "true" if x is not None else None,
choices=self.form_choices,
initial=self.get_initial_value(),
widget=forms.RadioSelect,
widget=forms.RadioSelect(
attrs={
"aria-label": self.aria_label
}
),
error_messages={
"required": self.required_error_message,
},

View file

@ -1,7 +1,11 @@
<!-- Exclude extraneous legend from radio elements -->
{% if not type == "radio" and not label_tag == "legend" %}
<{{ label_tag }}
class="{% if label_classes %} {{ label_classes }}{% endif %}{% if label_tag == 'legend' %} {{ legend_classes }}{% endif %}"
{% if not field.use_fieldset %}for="{{ widget.attrs.id }}"{% endif %}
>
{% endif %}
{% if span_for_text %}
<span>{{ field.label }}</span>
{% else %}
@ -16,4 +20,6 @@
{% endif %}
{% endif %}
{% if not type == "radio" and not label_tag == "legend" %}
</{{ label_tag }}>
{% endif %}

View file

@ -68,7 +68,11 @@ error messages, if necessary.
{% endif %}
{# this is the input field, itself #}
{% with aria_label=aria_label %}
{% include widget.template_name %}
{% endwith %}
{% if append_gov %}
<span class="padding-top-05 padding-left-2px">.gov </span>

View file

@ -169,5 +169,6 @@ def input_with_errors(context, field=None): # noqa: C901
) # -> {"widget": {"name": ...}}
context["widget"] = widget["widget"]
print("context: ", context)
return context