MDL-53071 course: Allow blank space input for section name
authorJun Pataleta <jun@moodle.com>
Thu, 11 Feb 2016 04:57:17 +0000 (12:57 +0800)
committerJun Pataleta <jun@moodle.com>
Tue, 23 Feb 2016 01:41:47 +0000 (09:41 +0800)
course/editsection_form.php

index 3c8e488..dfbbff2 100644 (file)
@@ -38,10 +38,6 @@ class editsection_form extends moodleform {
         $mform->addGroup($elementgroup, 'name_group', get_string('sectionname'), ' ', false);
         $mform->addGroupRule('name_group', array('name' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255))));
 
-        // Add rule for name_group to make sure that the section name is not blank if 'Use default section name'
-        // checkbox is unchecked.
-        $mform->addRule('name_group', get_string('required'), 'required', null, 'client');
-
         $mform->setDefault('usedefaultname', true);
         $mform->setType('name', PARAM_TEXT);
         $mform->disabledIf('name','usedefaultname','checked');
@@ -102,7 +98,7 @@ class editsection_form extends moodleform {
         $editoroptions = $this->_customdata['editoroptions'];
         $default_values = file_prepare_standard_editor($default_values, 'summary', $editoroptions,
                 $editoroptions['context'], 'course', 'section', $default_values->id);
-        $default_values->usedefaultname = (is_null($default_values->name));
+        $default_values->usedefaultname = (strval($default_values->name) === '');
         parent::set_data($default_values);
     }
 
@@ -116,8 +112,9 @@ class editsection_form extends moodleform {
         $data = parent::get_data();
         if ($data !== null) {
             $editoroptions = $this->_customdata['editoroptions'];
+            // Set name as an empty string if use default section name is checked.
             if (!empty($data->usedefaultname)) {
-                $data->name = null;
+                $data->name = '';
             }
             $data = file_postupdate_standard_editor($data, 'summary', $editoroptions,
                     $editoroptions['context'], 'course', 'section', $data->id);
@@ -141,15 +138,6 @@ class editsection_form extends moodleform {
             \core_availability\frontend::report_validation_errors($data, $errors);
         }
 
-        // Validate section name if 'Use default section name' is unchecked.
-        if (empty($data['usedefaultname'])) {
-            // Make sure the trimmed value of section name is not empty.
-            $trimmedname = trim($data['name']);
-            if (empty($trimmedname)) {
-                $errors['name_group'] = get_string('required');
-            }
-        }
-
         return $errors;
     }
 }