I have tried following the advice for using checkbox controllers in Moodle in a moodle_form. However, the setDefault() function doesn't seem to work as expected. I am able to set default values without using the checkbox controller; when I add the latter, the original value (which sets all of the member checkboxes to checked or unchecked) seems to override anything I attempt set as the default later on.
Here is the relevant code:
foreach ($groups as $group) {
$elname = 'linkedgroups[' . $group->id . ']';
$mform->addElement('advcheckbox', $elname, $group->name, null, array('group' => 2));
}
$this->add_checkbox_controller(2, null, array('style' => 'font-weight: bold;'), 0);
foreach ($groupsassignedids as $groupid) {
$mform->setDefault('linkedgroups['. $groupid . ']', 1);
}
You also can set default values adding javascript code. For example:
$("linkedgroups[0]").prop('checked', true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.