MDL-69165 Questions: Incorrect id used in init_submit_button function
authorHuong Nguyen <huongnv13@gmail.com>
Mon, 6 Jul 2020 04:31:05 +0000 (11:31 +0700)
committerHuong Nguyen <huongnv13@gmail.com>
Wed, 8 Jul 2020 03:54:24 +0000 (10:54 +0700)
mod/quiz/module.js
question/behaviour/interactive/renderer.php
question/behaviour/rendererbase.php
question/behaviour/upgrade.txt
question/qengine.js

index 9ede921..8409058 100644 (file)
@@ -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);
index 86681d5..91a76bc 100644 (file)
@@ -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;
     }
index c2a8a8a..76cc1a7 100644 (file)
@@ -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;
     }
index 235e953..e29055e 100644 (file)
@@ -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
index dc37efd..e14f918 100644 (file)
@@ -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);
 }