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.
# Not added by default.
aria_label = ""
title_label = ""
aria_label = title_label.join("")
def __init__(self, *args, **kwargs):
"""Extend the initialization of the form from RegistrarForm __init__"""
@ -262,7 +263,7 @@ class BaseYesNoForm(RegistrarForm):
initial=self.get_initial_value(),
widget=forms.RadioSelect(
attrs={
"aria-label": self.aria_label
# "aria-label": self.title_label
}
),
error_messages={

View file

@ -1,25 +1,24 @@
<!-- 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 %}
<{{ 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 %}
>
{% if legend_label %}
<h2>{{ legend_label }} </h2>
{% else %}
{% if span_for_text %}
<span>{{ field.label }}</span>
{% else %}
{{ field.label }}
{% endif %}
{% endif %}
{% if widget.attrs.required %}
<!--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 %}
<abbr class="usa-hint usa-hint--required" title="required">*</abbr>
{% endif %}
{% endif %}
{% if not type == "radio" and not label_tag == "legend" %}
</{{ label_tag }}>
{% endif %}
</{{ label_tag }}>

View file

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

View file

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