mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-72309 course: make category a required field in forms.
Course category fields were changed en masse from simple select elements to autocompletes in 93d72205, but weren't defined as required fields. This could lead to exceptions and/or unexpected behaviour if their values were cleared prior to form submission.
This commit is contained in:
parent
1a9bee69e6
commit
0645319e62
@ -84,6 +84,7 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
|
||||
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:create');
|
||||
$mform->addElement('autocomplete', 'defaults[category]', get_string('coursecategory'), $displaylist);
|
||||
$mform->addRule('defaults[category]', null, 'required', null, 'client');
|
||||
$mform->addHelpButton('defaults[category]', 'coursecategory');
|
||||
|
||||
$choices = array();
|
||||
|
@ -107,6 +107,7 @@ class copy_form extends \moodleform {
|
||||
$displaylist[$course->category] = \core_course_category::get($course->category, MUST_EXIST, true)->get_formatted_name();
|
||||
}
|
||||
$mform->addElement('autocomplete', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addRule('category', null, 'required', null, 'client');
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
|
||||
// Course visibility.
|
||||
|
@ -44,6 +44,7 @@ class cohort_edit_form extends moodleform {
|
||||
|
||||
$options = $this->get_category_options($cohort->contextid);
|
||||
$mform->addElement('autocomplete', 'contextid', get_string('context', 'role'), $options);
|
||||
$mform->addRule('contextid', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'idnumber', get_string('idnumber', 'cohort'), 'maxlength="254" size="50"');
|
||||
$mform->setType('idnumber', PARAM_RAW); // Idnumbers are plain text, must not be changed.
|
||||
|
@ -112,6 +112,7 @@ class core_course_deletecategory_form extends moodleform {
|
||||
|
||||
if ($displaylist) {
|
||||
$mform->addElement('autocomplete', 'newparent', get_string('movecategorycontentto'), $displaylist);
|
||||
$mform->addRule('newparent', null, 'required', null, 'client');
|
||||
if (in_array($this->coursecat->parent, $displaylist)) {
|
||||
$mform->setDefault('newparent', $this->coursecat->parent);
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ class core_course_editcategory_form extends moodleform {
|
||||
}
|
||||
|
||||
$mform->addElement('autocomplete', 'parent', get_string('parentcategory'), $options);
|
||||
$mform->addRule('parent', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30'));
|
||||
$mform->addRule('name', get_string('required'), 'required', null);
|
||||
|
@ -78,6 +78,7 @@ class course_edit_form extends moodleform {
|
||||
if (has_capability('moodle/course:create', $categorycontext)) {
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:create');
|
||||
$mform->addElement('autocomplete', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addRule('category', null, 'required', null, 'client');
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
$mform->setDefault('category', $category->id);
|
||||
} else {
|
||||
@ -94,6 +95,7 @@ class course_edit_form extends moodleform {
|
||||
->get_formatted_name();
|
||||
}
|
||||
$mform->addElement('autocomplete', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addRule('category', null, 'required', null, 'client');
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
} else {
|
||||
//keep current
|
||||
|
@ -71,6 +71,7 @@ class course_request_form extends moodleform {
|
||||
if (empty($CFG->lockrequestcategory)) {
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:request');
|
||||
$mform->addElement('autocomplete', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addRule('category', null, 'required', null, 'client');
|
||||
$mform->setDefault('category', $CFG->defaultrequestcategory);
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user