mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-03 16:32:15 +02:00
Merge pull request #959 from cisagov/rjm/957-checkbox-accessibility
957 - Fix accessible checkboxes in django admin
This commit is contained in:
commit
23696ac6a0
3 changed files with 28 additions and 1 deletions
|
@ -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">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue