Refactor legends from two separate legends to one combined legend

This commit is contained in:
Erin Song 2024-11-22 11:43:31 -08:00
parent e76571eb50
commit 36b78e9cea
No known key found for this signature in database
4 changed files with 22 additions and 21 deletions

View file

@ -241,7 +241,8 @@ class BaseYesNoForm(RegistrarForm):
# Option to append question to aria label for screenreader accessibility. # Option to append question to aria label for screenreader accessibility.
# Not added by default. # Not added by default.
aria_label = "" title_label = ""
aria_label = title_label.join("")
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Extend the initialization of the form from RegistrarForm __init__""" """Extend the initialization of the form from RegistrarForm __init__"""
@ -262,7 +263,7 @@ class BaseYesNoForm(RegistrarForm):
initial=self.get_initial_value(), initial=self.get_initial_value(),
widget=forms.RadioSelect( widget=forms.RadioSelect(
attrs={ attrs={
"aria-label": self.aria_label # "aria-label": self.title_label
} }
), ),
error_messages={ error_messages={

View file

@ -1,25 +1,24 @@
<!-- Exclude extraneous legend from radio elements --> <!-- Exclude extraneous legend from radio elements -->
{% if not type == "radio" and not label_tag == "legend" %}
<{{ label_tag }} <{{ label_tag }}
class="{% if label_classes %} {{ label_classes }}{% endif %}{% if label_tag == 'legend' %} {{ legend_classes }}{% endif %}" class="{% if label_classes %} {{ label_classes }}{% endif %}{% if label_tag == 'legend' %} {{ legend_classes }}{% endif %}"
{% if not field.use_fieldset %}for="{{ widget.attrs.id }}"{% endif %} {% if not field.use_fieldset %}for="{{ widget.attrs.id }}"{% endif %}
> >
{% endif %} {% if legend_label %}
<h2>{{ legend_label }} </h2>
{% else %}
{% if span_for_text %} {% if span_for_text %}
<span>{{ field.label }}</span> <span>{{ field.label }}</span>
{% else %} {% else %}
{{ field.label }} {{ field.label }}
{% endif %} {% endif %}
{% endif %}
{% if widget.attrs.required %} {% if widget.attrs.required %}
<!--Don't add asterisk to one-field forms --> <!--Don't add asterisk to one-field forms -->
{% if field.label == "Is your organization an election office?" or field.label == "What .gov domain do you want?" or field.label == "I read and agree to the requirements for operating a .gov domain." or field.label == "Please explain why there are no other employees from your organization we can contact to help us assess your eligibility for a .gov domain." %} {% if field.label == "Is your organization an election office?" or field.label == "What .gov domain do you want?" or field.label == "I read and agree to the requirements for operating a .gov domain." or field.label == "Please explain why there are no other employees from your organization we can contact to help us assess your eligibility for a .gov domain." or field.label == "Has other contacts" %}
{% else %} {% else %}
<abbr class="usa-hint usa-hint--required" title="required">*</abbr> <abbr class="usa-hint usa-hint--required" title="required">*</abbr>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if not type == "radio" and not label_tag == "legend" %}
</{{ label_tag }}> </{{ label_tag }}>
{% endif %}

View file

@ -17,17 +17,12 @@
{% endblock %} {% endblock %}
{% block form_fields %} {% block form_fields %}
<fieldset class="usa-fieldset margin-top-2"> <div class="margin-top-2">
<legend> {% with add_class="usa-radio__input--tile" add_legend_label="Are there other employees who can help verify your request?" %}
<h2>Are there other employees who can help verify your request?</h2>
</legend>
{% with add_class="usa-radio__input--tile" add_legend_class="usa-sr-only" %}
{% input_with_errors forms.0.has_other_contacts %} {% input_with_errors forms.0.has_other_contacts %}
{% endwith %} {% endwith %}
{# forms.0 is a small yes/no form that toggles the visibility of "other contact" formset #} {# forms.0 is a small yes/no form that toggles the visibility of "other contact" formset #}
</div>
</fieldset>
<div id="other-employees" class="other-contacts-form"> <div id="other-employees" class="other-contacts-form">
{% include "includes/required_fields.html" %} {% include "includes/required_fields.html" %}

View file

@ -57,6 +57,7 @@ def input_with_errors(context, field=None): # noqa: C901
legend_classes = [] legend_classes = []
group_classes = [] group_classes = []
aria_labels = [] aria_labels = []
legend_labels = []
# this will be converted to an attribute string # this will be converted to an attribute string
described_by = [] described_by = []
@ -90,6 +91,8 @@ def input_with_errors(context, field=None): # noqa: C901
label_classes.append(value) label_classes.append(value)
elif key == "add_legend_class": elif key == "add_legend_class":
legend_classes.append(value) legend_classes.append(value)
elif key == "add_legend_label":
legend_labels.append(value)
elif key == "add_group_class": elif key == "add_group_class":
group_classes.append(value) group_classes.append(value)
@ -149,6 +152,9 @@ def input_with_errors(context, field=None): # noqa: C901
if legend_classes: if legend_classes:
context["legend_classes"] = " ".join(legend_classes) context["legend_classes"] = " ".join(legend_classes)
if legend_labels:
context["legend_label"] = " ".join(legend_labels)
if group_classes: if group_classes:
context["group_classes"] = " ".join(group_classes) context["group_classes"] = " ".join(group_classes)