Attempting to make the form more compact by merging yes/no fields as an enable checkbox after another field to enable/disable the feature

This commit is contained in:
mark-nielsen 2007-07-24 08:12:12 +00:00
parent 807d0c3199
commit 862bd9cd9c
2 changed files with 33 additions and 6 deletions

View file

@ -489,6 +489,9 @@ function lesson_get_post_actions() {
function lesson_process_pre_save(&$lesson) { function lesson_process_pre_save(&$lesson) {
$lesson->timemodified = time(); $lesson->timemodified = time();
if (empty($lesson->timed)) {
$lesson->timed = 0;
}
if (empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) { if (empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) {
$lesson->timespent = 0; $lesson->timespent = 0;
} }

View file

@ -25,15 +25,23 @@ class mod_lesson_mod_form extends moodleform_mod {
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', null, 'required', null, 'client');
$mform->addElement('selectyesno', 'timed', get_string('timed', 'lesson')); // Create a text box that can be enabled/disabled for lesson time limit
$mform->setDefault('timed', 0); $timedgrp = array();
$mform->setHelpButton('timed', array('timed', get_string('timed', 'lesson'), 'lesson')); $timedgrp[] = &$mform->createElement('text', 'maxtime');
$timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable'));
$mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false);
$mform->disabledIf('timedgrp', 'timed');
$mform->addElement('text', 'maxtime', get_string('maxtime', 'lesson')); // Add numeric rule to text field
$timedgrprules = array();
$timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client');
$mform->addGroupRule('timedgrp', $timedgrprules);
// Rest of group setup
$mform->setDefault('timed', 0);
$mform->setDefault('maxtime', 20); $mform->setDefault('maxtime', 20);
$mform->addRule('maxtime', null, 'required', null, 'client');
$mform->addRule('maxtime', null, 'numeric', null, 'client');
$mform->setType('maxtime', PARAM_INT); $mform->setType('maxtime', PARAM_INT);
$mform->setHelpButton('timedgrp', array('timed', get_string('timed', 'lesson'), 'lesson'));
$numbers = array(); $numbers = array();
for ($i=20; $i>1; $i--) { for ($i=20; $i>1; $i--) {
@ -308,5 +316,21 @@ class mod_lesson_mod_form extends moodleform_mod {
} }
} }
} }
/**
* Enforce validation rules here
*
* @param object $data Post data to validate
* @return array
**/
function validation($data) {
$errors = array();
if (empty($data['maxtime']) and !empty($data['timed'])) {
$errors['timedgrp'] = get_string('err_numeric', 'form');
}
return $errors;
}
} }
?> ?>