Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-35395

Provide some way to disable the core_formchangechecker for a given form

    XMLWordPrintable

Details

    • MOODLE_23_STABLE, MOODLE_24_STABLE
    • MOODLE_23_STABLE
    • Hide

      (some of the dirty ones commented in the description of this issue)

      Show
      (some of the dirty ones commented in the description of this issue)
    • Hide

      This test script demonstrates the problem. If you run it, you will get a JavaScript error. The two comments indicate two ways to make the error go away. If you are doing clever Ajax things then you need the new disable_form_change_checker way of doing it.

      <?php
      require_once('config.php');
      require_once($CFG->libdir . '/formslib.php');
       
      $PAGE->set_context(context_system::instance());
      $PAGE->set_url('/test.php');
       
      class myform extends moodleform {
          protected function definition() {
              // Uncomment the following line to make the JavaScript error go away.
              // $this->_form->disable_form_change_checker();
              $this->add_action_buttons();
          }
       
          public function render() {
              ob_start();
              $this->display();
              return ob_get_clean();
          }
      }
       
      $mform = new myform();
       
      echo $OUTPUT->header();
      // For some reason, render a form without outputting it. The JavaScript error
      // will also go away if you add echo to the start of the next line.
      $mform->render();
      echo $OUTPUT->footer();

      Show
      This test script demonstrates the problem. If you run it, you will get a JavaScript error. The two comments indicate two ways to make the error go away. If you are doing clever Ajax things then you need the new disable_form_change_checker way of doing it. <?php require_once('config.php'); require_once($CFG->libdir . '/formslib.php');   $PAGE->set_context(context_system::instance()); $PAGE->set_url('/test.php');   class myform extends moodleform { protected function definition() { // Uncomment the following line to make the JavaScript error go away. // $this->_form->disable_form_change_checker(); $this->add_action_buttons(); }   public function render() { ob_start(); $this->display(); return ob_get_clean(); } }   $mform = new myform();   echo $OUTPUT->header(); // For some reason, render a form without outputting it. The JavaScript error // will also go away if you add echo to the start of the next line. $mform->render(); echo $OUTPUT->footer();

    Description

      At some point core_formchangechecker module was added to all forms in Moodle.

      And it's great, but for some old/legacy/contrib forms still performing multiple submits and not fully migrated to have pure js alternatives (nested elements... actions at distance...).

      Right now it's really hacky to disable such core_formchangechecker from a given form:

      • Use the "ignoredirty" class at field level (does not work at form level and it's imperfect coz does not mark the form as submitted apparently.
      • Hack all the submit calls, prepending "M.core_formchangechecker.set_form_submitted()" hacky.
      • Overwrite some core stuff or hack it to avoid the inclusion of the module.

      All them imperfect, dirty, hacky.

      So it would be great to have some documented way to simply skip the use of the module in a form programatically. Say, supporting the "ignoredirty" at form level (module conditionally included based on that...) or whatever.

      Ciao

      Attachments

        Activity

          People

            timhunt Tim Hunt
            stronk7 Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Frédéric Massart Frédéric Massart
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              12/Nov/12