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

Form field modgrade creates elements with the same hard-coded id attribute

    XMLWordPrintable

    Details

      Description

      While working on some Behat tests for the Workshop module, I noticed warnings like

      Warning: DOMDocument::importNode(): ID id_modgrade_scale already defined in .../vendor/behat/mink-browserkit-driver/src/Behat/Mink/Driver/BrowserKitDriver.php on line 675
      

      This is caused by multiple form fields of the type modgrade on the page. The elements created by this field (two select fields and one text input field) have their id attribute not respecting the field name, so they end with the same value.

      This is not common case as the field is typically used in mod_forms only and there is almost always the field used just once. But the Workshop uses it in when editing the assessment form via mod/workshop/accumulative/edit_form.php.

      Steps to reproduce

      Put the following script into the root folder of your Moodle and visit it from the browser.

      <?php
       
      require(__DIR__.'/config.php');
      require_once($CFG->libdir.'/formslib.php');
       
      class foo_form extends moodleform {
       
          public function definition() {
              
              $mform = $this->_form;
              
              $mform->addElement('modgrade', 'grade1', 'Grade 1');
              $mform->addElement('modgrade', 'grade2', 'Grade 2');
          }
      }
       
      $PAGE->set_context(context_system::instance());
      $PAGE->set_url('/');
       
      $f = new foo_form();
       
      echo $OUTPUT->header();
      $f->display();
      echo $OUTPUT->footer();
      

      Expected behaviour

      All the elements in the form have unique id attribute.

      Current buggy behaviour

      There are two elements with id="id_modgrade_type", two elements with id="id_modgrade_scale" and two elements with id="id_modgrade_point"

      I think this is a regression of MDL-22999 where the modgrade field was changed from subclassing MoodleQuickForm_select instead of MoodleQuickForm_group (commit 59766233) - and by the way, the signature of addField() call was changed by that change and apparently not all places were fixed, such as the mentioned Workshop.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mudrd8mz David Mudrák (@mudrd8mz)
                Reporter:
                mudrd8mz David Mudrák (@mudrd8mz)
                Peer reviewer:
                Rajesh Taneja
                Integrator:
                David Monllaó
                Tester:
                Adrian Greeve
                Participants:
                Component watchers:
                Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Jake Dallimore, Jun Pataleta, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Mar/16