MDL-74112 course: Support multiple mforms in format chooser
The format chooser JS assumes that it is the only mform on the page. If it is not, and another mform appears before it, then the jump will not work. This change: * updates the formatchooser to modern JS * allows multiple forms to exist on the page * stops using id fields * always hide the format selection button
This commit is contained in:
@@ -19,8 +19,7 @@ class course_edit_form extends moodleform {
|
||||
global $CFG, $PAGE;
|
||||
|
||||
$mform = $this->_form;
|
||||
$PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser',
|
||||
array(array('formid' => $mform->getAttribute('id'))));
|
||||
$PAGE->requires->js_call_amd('core_course/formatchooser', 'init');
|
||||
|
||||
$course = $this->_customdata['course']; // this contains the data of this form
|
||||
$category = $this->_customdata['category'];
|
||||
@@ -220,13 +219,18 @@ class course_edit_form extends moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'format', get_string('format'), $formcourseformats);
|
||||
$mform->addElement('select', 'format', get_string('format'), $formcourseformats, [
|
||||
'data-formatchooser-field' => 'selector',
|
||||
]);
|
||||
$mform->addHelpButton('format', 'format');
|
||||
$mform->setDefault('format', $courseconfig->format);
|
||||
|
||||
// Button to update format-specific options on format change (will be hidden by JavaScript).
|
||||
$mform->registerNoSubmitButton('updatecourseformat');
|
||||
$mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));
|
||||
$mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'), [
|
||||
'data-formatchooser-field' => 'updateButton',
|
||||
'class' => 'd-none',
|
||||
]);
|
||||
|
||||
// Just a placeholder for the course format options.
|
||||
$mform->addElement('hidden', 'addcourseformatoptionshere');
|
||||
|
||||
Reference in New Issue
Block a user