Merge pull request #959 from cisagov/rjm/957-checkbox-accessibility

957 - Fix accessible checkboxes in django admin
This commit is contained in:
rachidatecs 2023-08-30 15:12:53 -04:00 committed by GitHub
commit 23696ac6a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

@ -17,7 +17,7 @@ Load our custom filters to extract info from the django generated markup.
<thead>
<tr>
{% if results.0.form %}
{% if results.0|contains_checkbox %}
{# .gov - hardcode the select all checkbox #}
<th scope="col" class="action-checkbox-column" title="Toggle all">
<div class="text">

View file

@ -40,3 +40,11 @@ def slice_after(value, substring):
result = value[index + len(substring) :]
return result
return value
@register.filter
def contains_checkbox(html_list):
for html_string in html_list:
if re.search(r'<input[^>]*type="checkbox"', html_string):
return True
return False

View file

@ -8,6 +8,7 @@ from registrar.templatetags.custom_filters import (
extract_a_text,
find_index,
slice_after,
contains_checkbox,
)
@ -83,3 +84,21 @@ class CustomFiltersTestCase(TestCase):
self.assertEqual(
result, value
) # Should return the original value if substring not found
def test_contains_checkbox_with_checkbox(self):
# Test the filter when HTML list contains a checkbox
html_list = [
'<input type="checkbox" name="_selected_action">',
"<div>Some other HTML content</div>",
]
result = contains_checkbox(html_list)
self.assertTrue(result) # Expecting True
def test_contains_checkbox_without_checkbox(self):
# Test the filter when HTML list does not contain a checkbox
html_list = [
"<div>Some HTML content without checkbox</div>",
"<p>More HTML content</p>",
]
result = contains_checkbox(html_list)
self.assertFalse(result) # Expecting False