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 of control key to select. 我尝试使用 selectMulitple,它允许按住控制键来选择选项。
$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);
解决方案
简短的回答是否定的。您需要使用控制键在一个选择中选择多个项目。
不过,您可以使用一系列复选框,如下所示:
$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.
}
}
推荐阅读
- django - Django 只允许用户进入他们自己的多个页面的个人资料
- linux - Log-rotate 压缩后删除原始文件
- c - 如何在while循环内传递多个命令
- tensorflow - 出现错误:尝试在 tensorflow 中训练 mobilenet 时,配置值 cuda 未在任何 .rc 文件中定义
- java - 如何读取 Drools 内存以检测部分匹配的规则
- angular - 如何使用与 Firebase 提供的电子邮件服务不同的电子邮件服务来验证电子邮件和更改密码?
- sql - 更新...限制 1 没有 PK 的 PostgreSQL
- c# - .NET Core 2 WebAPI CORS 与 Angular 4 前端和 Windows Auth 的问题
- kotlin - 在类jooq中使用primarykey和references方法有什么好处
- c++ - 如何在 C++ 中将 long int 打印到屏幕上?