diff --git a/xblocks_contrib/problem/capa/capa_problem.py b/xblocks_contrib/problem/capa/capa_problem.py
index 00a9e6f3..db09d703 100644
--- a/xblocks_contrib/problem/capa/capa_problem.py
+++ b/xblocks_contrib/problem/capa/capa_problem.py
@@ -1150,7 +1150,19 @@ def _preprocess_problem(self, tree, minimal_init): # private
return problem_data
- def response_a11y_data( # pylint: disable=too-many-locals,too-many-branches
+ @staticmethod
+ def _preceding_prompt_ids(response, responsetype_id):
+ """Assign ids to contiguous preceding ``
`` siblings and return them in document order."""
+ ids = []
+ sibling = response.getprevious()
+ while sibling is not None and isinstance(sibling.tag, str) and sibling.tag.lower() == "p":
+ pid = sibling.get("id") or f"prompt_{responsetype_id}_{len(ids) + 1}"
+ sibling.set("id", pid)
+ ids.append(pid)
+ sibling = sibling.getprevious()
+ return list(reversed(ids))
+
+ def response_a11y_data( # pylint: disable=too-many-locals,too-many-branches,too-many-statements
self, response, inputfields, responsetype_id, problem_data
):
"""
@@ -1193,12 +1205,21 @@ def response_a11y_data( # pylint: disable=too-many-locals,too-many-branches
if group_description_ids:
response.set("multiinput-group_description_ids", " ".join(group_description_ids))
+ preceding_prompt_ids = (
+ self._preceding_prompt_ids(response, responsetype_id)
+ if inputfields[0].tag in ACCESSIBLE_CAPA_INPUT_TYPES
+ else []
+ )
+
for inputfield in inputfields:
- problem_data[inputfield.get("id")] = {
+ entry = {
"group_label": group_label_tag_text,
"label": HTML(inputfield.attrib.get("label", "")),
"descriptions": {},
}
+ if preceding_prompt_ids:
+ entry["additional_describedby_ids"] = list(preceding_prompt_ids)
+ problem_data[inputfield.get("id")] = entry
else:
# Extract label value from