diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 705594dc3f0..7f6fcdfccb5 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -359,6 +359,19 @@ class question_attempt { return 'q' . $this->usageid . ':' . $this->slot . '_'; } + /** + * When the question is rendered, this unique id is added to the + * outer div of the question. It can be used to uniquely reference + * the question from JavaScript. + * + * Note, this is not truly unique. It will be changed in Moodle 3.7. See MDL-65029. + * + * @return string id added to the outer
when the question is rendered. + */ + public function get_outer_question_div_unique_id() { + return 'q' . $this->slot; + } + /** * Get one of the steps in this attempt. * diff --git a/question/engine/renderer.php b/question/engine/renderer.php index 17246d59044..6d19acbf753 100644 --- a/question/engine/renderer.php +++ b/question/engine/renderer.php @@ -89,7 +89,7 @@ class core_question_renderer extends plugin_renderer_base { $output = ''; $output .= html_writer::start_tag('div', array( - 'id' => 'q' . $qa->get_slot(), + 'id' => $qa->get_outer_question_div_unique_id(), 'class' => implode(' ', array( 'que', $qa->get_question()->qtype->name(), diff --git a/question/type/ddimageortext/rendererbase.php b/question/type/ddimageortext/rendererbase.php index 58bca8546f8..bc0ad5e1a07 100644 --- a/question/type/ddimageortext/rendererbase.php +++ b/question/type/ddimageortext/rendererbase.php @@ -112,7 +112,7 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere } $output .= html_writer::tag('div', $droparea . $dragitems . $dropzones . $hiddens, array('class' => 'ddarea')); - $topnode = 'div#q'.$qa->get_slot().' div.ddarea'; + $topnode = 'div#' . $qa->get_outer_question_div_unique_id() . ' div.ddarea'; $params = array('drops' => $question->places, 'topnode' => $topnode, 'readonly' => $options->readonly); diff --git a/question/type/ddmarker/renderer.php b/question/type/ddmarker/renderer.php index 45e119bc7e2..d163a6451e4 100644 --- a/question/type/ddmarker/renderer.php +++ b/question/type/ddmarker/renderer.php @@ -96,7 +96,7 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { $visibledropzones = array(); } - $topnode = 'div#q'.$qa->get_slot(); + $topnode = 'div#' . $qa->get_outer_question_div_unique_id(); $params = array('dropzones' => $visibledropzones, 'topnode' => $topnode, 'readonly' => $options->readonly); diff --git a/question/type/ddwtos/renderer.php b/question/type/ddwtos/renderer.php index 7425082df2a..05357e253c6 100644 --- a/question/type/ddwtos/renderer.php +++ b/question/type/ddwtos/renderer.php @@ -54,7 +54,7 @@ class qtype_ddwtos_renderer extends qtype_elements_embedded_in_question_text_ren $params = array( 'inputids' => $inputids, - 'topnode' => 'div.que.ddwtos#q' . $qa->get_slot(), + 'topnode' => 'div.que.ddwtos#' . $qa->get_outer_question_div_unique_id(), 'readonly' => $options->readonly );