From 069813815988239fdafca1479709d063cce48413 Mon Sep 17 00:00:00 2001 From: Leon Stringer Date: Sun, 1 Dec 2024 05:56:55 +0000 Subject: [PATCH] CTP-4114 Fix: Cannot add jQuery after page output! (#39) Fix warning "Can not add jQuery plugins after starting page output!" when on course's Default Activity Completion page (course/defaultcompletion.php). --- mod_form.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/mod_form.php b/mod_form.php index 2c9fd29..90f2bda 100644 --- a/mod_form.php +++ b/mod_form.php @@ -44,17 +44,21 @@ public function definition() { global $PAGE, $CFG; - $PAGE->requires->jquery(); - - $module = [ - 'name' => 'mod_coursework', - 'fullpath' => '/mod/coursework/mod_form.js', - 'requires' => [ - 'node', - 'ajax', - ]]; - - $PAGE->requires->js_init_call('M.mod_coursework.init', [], true, $module); + // Don't include jQuery when not on this module's settings page, for + // example, if on the default activity completion page. See MDL-78528. + if ($PAGE->pagetype === 'mod-coursework-mod') { + $PAGE->requires->jquery(); + + $module = [ + 'name' => 'mod_coursework', + 'fullpath' => '/mod/coursework/mod_form.js', + 'requires' => [ + 'node', + 'ajax', + ]]; + + $PAGE->requires->js_init_call('M.mod_coursework.init', [], true, $module); + } $this->set_form_attributes();