Skip to content

Commit eab1363

Browse files
sym9symon.vezina
andauthored
Added global required fields notice for WCAG H90 compliance (#14962)
* Added global required fields notice for WCAG H90 compliance * display_tags.py add and removed blank line * Added setting/env variable DD_SHOW_A11Y_REQUIRED_FIELDS_NOTICE --------- Co-authored-by: symon.vezina <symon.vezina@hrsdc-rhdcc.gc.ca>
1 parent b31cf9a commit eab1363

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

dojo/context_processors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def globalize_vars(request):
2222
"SHOW_PLG_LINK": True,
2323
# V3 Feature Flags
2424
"V3_FEATURE_LOCATIONS": settings.V3_FEATURE_LOCATIONS,
25+
"SHOW_A11Y_REQUIRED_FIELDS_NOTICE": settings.SHOW_A11Y_REQUIRED_FIELDS_NOTICE,
2526
}
2627

2728
additional_banners = []

dojo/settings/settings.dist.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@
127127
# Falls back to a plain queryset on any error (logged).
128128
DD_WATSON_INDEX_PREFETCH_ENABLED=(bool, True),
129129
DD_FOOTER_VERSION=(str, ""),
130-
# models should be passed to celery by ID, default is False (for now)
130+
# Toggle for the highly accessible notice at the top of forms ("Required fields are marked with an asterisk*")
131+
DD_SHOW_A11Y_REQUIRED_FIELDS_NOTICE=(bool, True),
131132
DD_DATABASE_ENGINE=(str, "django.db.backends.postgresql"),
132133
DD_DATABASE_HOST=(str, "postgres"),
133134
DD_DATABASE_NAME=(str, "defectdojo"),
@@ -625,6 +626,9 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
625626
# Used to configure a custom version in the footer of the base.html template.
626627
FOOTER_VERSION = env("DD_FOOTER_VERSION")
627628

629+
# Toggle for the highly accessible notice at the top of forms ("Required fields are marked with an asterisk*")
630+
SHOW_A11Y_REQUIRED_FIELDS_NOTICE = env("DD_SHOW_A11Y_REQUIRED_FIELDS_NOTICE")
631+
628632
# V3 Feature Flags
629633
V3_FEATURE_LOCATIONS = env("DD_V3_FEATURE_LOCATIONS")
630634

dojo/templates/dojo/form_fields.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load event_tags %}
2+
{% load display_tags %}
23
{% block css %}
34
{{ form.media.css }}
45
{% endblock %}
@@ -17,6 +18,16 @@
1718
{{ field }}
1819
{% endfor %}
1920

21+
{% if form|has_required_field and SHOW_A11Y_REQUIRED_FIELDS_NOTICE %}
22+
<div class="form-group">
23+
<div class="col-sm-offset-2 col-sm-10">
24+
<p class="help-block">
25+
<em>Required fields are marked with an asterisk</em><sup>*</sup>
26+
</p>
27+
</div>
28+
</div>
29+
{% endif %}
30+
2031
{% for field in form.visible_fields %}
2132
<div class="form-group{% if field.errors %} has-error{% endif %}">
2233
{% if field|is_checkbox %}

dojo/templates_classic/dojo/form_fields.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load event_tags %}
2+
{% load display_tags %}
23
{% block css %}
34
{{ form.media.css }}
45
{% endblock %}
@@ -16,6 +17,16 @@
1617
{{ field }}
1718
{% endfor %}
1819

20+
{% if form|has_required_field and SHOW_A11Y_REQUIRED_FIELDS_NOTICE %}
21+
<div class="form-group">
22+
<div class="col-sm-offset-2 col-sm-10">
23+
<p class="help-block">
24+
<em>Required fields are marked with an asterisk</em><sup>*</sup>
25+
</p>
26+
</div>
27+
</div>
28+
{% endif %}
29+
1930
{% for field in form.visible_fields %}
2031
<div class="form-group{% if field.errors %} has-error{% endif %}">
2132
{% if field|is_checkbox %}

dojo/templatetags/display_tags.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,3 +1167,11 @@ def import_history(finding, *, autoescape=True):
11671167
list_of_status_changes += "<b>" + status_change.created.strftime("%b %d, %Y, %H:%M:%S") + "</b>: " + status_change.get_action_display() + "<br/>"
11681168

11691169
return mark_safe(html % (list_of_status_changes))
1170+
1171+
1172+
@register.filter
1173+
def has_required_field(form):
1174+
"""Returns True if the form has at least one required field"""
1175+
if not form:
1176+
return False
1177+
return any(field.field.required for field in form)

0 commit comments

Comments
 (0)