From 31a3d4d643bfc9192738bd7ecc28bf92a7aa747a Mon Sep 17 00:00:00 2001 From: Leon Stringer Date: Thu, 22 Aug 2024 21:07:32 +0100 Subject: [PATCH] 594 Fix formChild is null When a student completed a questionnaire then shown the "Thank you for completing this Questionnaire" page there was a JavaScript error: Uncaught TypeError: formChild is null This was because the JavaScript for the questions form was being inadvertently loaded for the Thank you page where this form is not present. --- classes/output/renderer.php | 1 + questionnaire.class.php | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 5bc029b3..456370e3 100755 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -147,6 +147,7 @@ public function complete_formstart($action, $hiddeninputs=[]) { foreach ($hiddeninputs as $name => $value) { $output .= \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $name, 'value' => $value]) . "\n"; } + $this->page->requires->js_init_call('M.mod_questionnaire.init_attempt_form', null, false, questionnaire_get_js_module()); return $output; } diff --git a/questionnaire.class.php b/questionnaire.class.php index e366f70b..004d4609 100644 --- a/questionnaire.class.php +++ b/questionnaire.class.php @@ -270,10 +270,6 @@ public function view() { $PAGE->set_title(format_string($this->name)); $PAGE->set_heading(format_string($this->course->fullname)); - - // Initialise the JavaScript. - $PAGE->requires->js_init_call('M.mod_questionnaire.init_attempt_form', null, false, questionnaire_get_js_module()); - $message = $this->user_access_messages($USER->id, true); if ($message !== false) { $this->page->add_to_page('notifications', $message);