From 579da44a7067bdd0fc9686e2c40f1e7964d71808 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Mon, 6 Jul 2020 11:31:05 +0700 Subject: [PATCH] MDL-69165 Questions: Incorrect id used in init_submit_button function --- mod/quiz/module.js | 4 ++-- question/behaviour/interactive/renderer.php | 2 +- question/behaviour/rendererbase.php | 2 +- question/behaviour/upgrade.txt | 6 ++++++ question/qengine.js | 12 ++++++++---- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mod/quiz/module.js b/mod/quiz/module.js index 9ede9214fb2..84090582b2d 100644 --- a/mod/quiz/module.js +++ b/mod/quiz/module.js @@ -194,9 +194,9 @@ M.mod_quiz.nav.init = function(Y) { pageno = 0; } - var questionidmatch = this.get('href').match(/#q(\d+)/); + var questionidmatch = this.get('href').match(/#question-(\d+)-(\d+)/); if (questionidmatch) { - form.set('action', form.get('action') + '#q' + questionidmatch[1]); + form.set('action', form.get('action') + questionidmatch[0]); } nav_to_page(pageno); diff --git a/question/behaviour/interactive/renderer.php b/question/behaviour/interactive/renderer.php index 86681d5de92..91a76bcde31 100644 --- a/question/behaviour/interactive/renderer.php +++ b/question/behaviour/interactive/renderer.php @@ -66,7 +66,7 @@ class qbehaviour_interactive_renderer extends qbehaviour_renderer { $output = html_writer::empty_tag('input', $attributes); if (empty($attributes['disabled'])) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', - array($attributes['id'], $qa->get_slot())); + array($attributes['id'])); } return $output; } diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index c2a8a8a7d7b..76cc1a7f636 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -243,7 +243,7 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { $output = html_writer::empty_tag('input', $attributes); if (!$options->readonly) { $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', - array($attributes['id'], $qa->get_slot())); + array($attributes['id'])); } return $output; } diff --git a/question/behaviour/upgrade.txt b/question/behaviour/upgrade.txt index 235e9530d40..e29055eba61 100644 --- a/question/behaviour/upgrade.txt +++ b/question/behaviour/upgrade.txt @@ -1,5 +1,11 @@ This files describes API changes for question behaviour plugins. +=== 4.0 === + +1) The slot parameter of method M.core_question_engine.init_submit_button now removed. + The method will get the unique id by using the 'Check' button element. + + === 3.1 === 1) The standard behaviours that use a 'Check' button have all been changed so diff --git a/question/qengine.js b/question/qengine.js index dc37efd7702..e14f918cd74 100644 --- a/question/qengine.js +++ b/question/qengine.js @@ -123,14 +123,18 @@ M.core_question_engine.questionformalreadysubmitted = false; /** * Initialise a question submit button. This saves the scroll position and * sets the fragment on the form submit URL so the page reloads in the right place. - * @param id the id of the button in the HTML. - * @param slot the number of the question_attempt within the usage. + * @param button the id of the button in the HTML. */ -M.core_question_engine.init_submit_button = function(Y, button, slot) { +M.core_question_engine.init_submit_button = function(Y, button) { + var totalQuestionsInPage = document.querySelectorAll('div.que').length; var buttonel = document.getElementById(button); + var outeruniqueid = buttonel.closest('.que').id; Y.on('click', function(e) { M.core_scroll_manager.save_scroll_pos(Y, button); - buttonel.form.action = buttonel.form.action + '#q' + slot; + if (totalQuestionsInPage > 1) { + // Only change the form action if the page have more than one question. + buttonel.form.action = buttonel.form.action + '#' + outeruniqueid; + } }, buttonel); } -- 2.43.0