-
Bug
-
Resolution: Fixed
-
Minor
-
2.7.12, 2.8.10, 2.9.4, 3.0.2
-
MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE, MOODLE_30_STABLE
-
MOODLE_29_STABLE, MOODLE_30_STABLE
-
MDL-52873-master-modgradeid -
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.