Correct place to require jquery in question renderers

Correct place to require jquery in question renderers

by Oleg Sychev -
Number of replies: 1
Picture of Core developers Picture of Plugin developers

We used to just having 

global $PAGE;
$PAGE->requires->jquery();

in global code of renderer.php file, and it worked fine in general use.

But then we found that this gives problems for the popup window where a teacher can leave a comment or override grade.

Like this:

Can not add jQuery plugins after starting page output!

  • line 491 of /lib/outputrequirementslib.php: call to debugging()
  • line 436 of /lib/outputrequirementslib.php: call to page_requirements_manager->jquery_plugin()
  • line 33 of /question/type/correctwriting/renderer.php: call to page_requirements_manager->jquery()
  • line 201 of /lib/outputfactories.php: call to include_once()
  • line 389 of /lib/outputfactories.php: call to renderer_factory_base->standard_renderer_classnames()
  • line 2120 of /lib/outputlib.php: call to theme_overridden_renderer_factory->get_renderer()
  • line 861 of /lib/pagelib.php: call to theme_config->get_renderer()
  • line 276 of /question/type/questionbase.php: call to moodle_page->get_renderer()
  • line 840 of /question/engine/questionattempt.php: call to question_definition->get_renderer()
  • line 449 of /question/engine/questionusage.php: call to question_attempt->render()
  • line 1625 of /mod/quiz/attemptlib.php: call to question_usage_by_activity->render_question()
  • line 113 of /mod/quiz/comment.php: call to quiz_attempt->render_question_for_commenting()
What is the supposed place to perform requiring JQuery for a question renderer?
Average of ratings: -