Commit 62d129fd by Jeff LaJoie Committed by GitHub

Merge pull request #14298 from edx/jlajoie/TNL-6095

Adds trailing_text id to input describedby
parents adad6b2e 1c0a60eb
...@@ -328,9 +328,16 @@ class InputTypeBase(object): ...@@ -328,9 +328,16 @@ class InputTypeBase(object):
} }
# Generate the list of ids to be used with the aria-describedby field. # Generate the list of ids to be used with the aria-describedby field.
descriptions = list()
# If there is trailing text, add the id as the first element to the list before adding the status id
if 'trailing_text' in self.loaded_attributes and self.loaded_attributes['trailing_text']:
trailing_text_id = 'trailing_text_' + self.input_id
descriptions.append(trailing_text_id)
# Every list should contain the status id # Every list should contain the status id
status_id = 'status_' + self.input_id status_id = 'status_' + self.input_id
descriptions = list([status_id]) descriptions.append(status_id)
descriptions.extend(self.response_data.get('descriptions', {}).keys()) descriptions.extend(self.response_data.get('descriptions', {}).keys())
description_ids = ' '.join(descriptions) description_ids = ' '.join(descriptions)
context.update( context.update(
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
size="${size}" size="${size}"
% endif % endif
/> />
<span class="trailing_text">${trailing_text}</span> <span class="trailing_text" id="trailing_text_${id}">${trailing_text}</span>
<%include file="status_span.html" args="status=status, status_id=id"/> <%include file="status_span.html" args="status=status, status_id=id"/>
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
style="display:none;" style="display:none;"
% endif % endif
/> />
<span class="trailing_text">${trailing_text}</span> <span class="trailing_text" id="trailing_text_${id}">${trailing_text}</span>
<%include file="status_span.html" args="status=status, status_id=id"/> <%include file="status_span.html" args="status=status, status_id=id"/>
......
...@@ -37,6 +37,8 @@ lookup_tag = inputtypes.registry.get_class_for_tag ...@@ -37,6 +37,8 @@ lookup_tag = inputtypes.registry.get_class_for_tag
DESCRIBEDBY = HTML('aria-describedby="status_{status_id} desc-1 desc-2"') DESCRIBEDBY = HTML('aria-describedby="status_{status_id} desc-1 desc-2"')
# Use TRAILING_TEXT_DESCRIBEDBY when trailing_text is not null
TRAILING_TEXT_DESCRIBEDBY = HTML('aria-describedby="trailing_text_{trailing_text_id} status_{status_id} desc-1 desc-2"')
DESCRIPTIONS = OrderedDict([('desc-1', 'description text 1'), ('desc-2', 'description text 2')]) DESCRIPTIONS = OrderedDict([('desc-1', 'description text 1'), ('desc-2', 'description text 2')])
RESPONSE_DATA = { RESPONSE_DATA = {
'label': 'question text 101', 'label': 'question text 101',
...@@ -361,7 +363,7 @@ class TextLineTest(unittest.TestCase): ...@@ -361,7 +363,7 @@ class TextLineTest(unittest.TestCase):
'trailing_text': expected_text, 'trailing_text': expected_text,
'preprocessor': None, 'preprocessor': None,
'response_data': RESPONSE_DATA, 'response_data': RESPONSE_DATA,
'describedby_html': DESCRIBEDBY.format(status_id=prob_id) 'describedby_html': TRAILING_TEXT_DESCRIBEDBY.format(trailing_text_id=prob_id, status_id=prob_id)
} }
self.assertEqual(context, expected) self.assertEqual(context, expected)
...@@ -1295,7 +1297,7 @@ class FormulaEquationTest(unittest.TestCase): ...@@ -1295,7 +1297,7 @@ class FormulaEquationTest(unittest.TestCase):
'inline': False, 'inline': False,
'trailing_text': expected_text, 'trailing_text': expected_text,
'response_data': RESPONSE_DATA, 'response_data': RESPONSE_DATA,
'describedby_html': DESCRIBEDBY.format(status_id=prob_id) 'describedby_html': TRAILING_TEXT_DESCRIBEDBY.format(trailing_text_id=prob_id, status_id=prob_id)
} }
self.assertEqual(context, expected) self.assertEqual(context, expected)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment