Mform SELECT - Moodle
Mform SELECT - Moodle
Is there mform select tag, when option is selected so that it highlights and stick to the selected one and select more options without the use select 的控制键。我尝试使用 selectMultiple,它允许按住控制键 select 选项。
$select = $mform->addElement('select', 'course', get_string('course', 'core_course'), $options);
$mform->addHelpButton('course', 'course', 'core_course');
$mform->addRule('course', null, 'required', null, 'client');
$mform->setType('course', PARAM_INT);
$select->setMultiple(true);
简短的回答是否定的。您需要使用控制键 select 多个项目 select.
不过您可以使用一系列复选框,如下所示:
$courses = core_course_category::get(0)->get_courses(
array('recursive' => true, 'sort' => array('fullname' => 1)));
foreach ($courses as $course) {
$mform->addElement('advcheckbox', "courses[{$course->id}]",
format_string($course->fullname), null, array('group' => 1));
}
$this->add_checkbox_controller(1);
然后在你的编辑代码中,使用类似这样的东西
for each($formdata->courses as $courseid => $selected) {
if ($selected) {
// User selected this course.
} else {
// User unselected this course.
}
}
Is there mform select tag, when option is selected so that it highlights and stick to the selected one and select more options without the use select 的控制键。我尝试使用 selectMultiple,它允许按住控制键 select 选项。
$select = $mform->addElement('select', 'course', get_string('course', 'core_course'), $options);
$mform->addHelpButton('course', 'course', 'core_course');
$mform->addRule('course', null, 'required', null, 'client');
$mform->setType('course', PARAM_INT);
$select->setMultiple(true);
简短的回答是否定的。您需要使用控制键 select 多个项目 select.
不过您可以使用一系列复选框,如下所示:
$courses = core_course_category::get(0)->get_courses(
array('recursive' => true, 'sort' => array('fullname' => 1)));
foreach ($courses as $course) {
$mform->addElement('advcheckbox', "courses[{$course->id}]",
format_string($course->fullname), null, array('group' => 1));
}
$this->add_checkbox_controller(1);
然后在你的编辑代码中,使用类似这样的东西
for each($formdata->courses as $courseid => $selected) {
if ($selected) {
// User selected this course.
} else {
// User unselected this course.
}
}