From: sam_marshall Date: Wed, 6 Dec 2006 14:50:57 +0000 (+0000) Subject: MDL-7816 Added optional (checkbox) facility to quickform dateselector X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=de312b53bb09d79416cc9380e321f390dab304a0;p=moodle.git MDL-7816 Added optional (checkbox) facility to quickform dateselector --- diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index 1d2747a60e..8c7765d1a9 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -20,9 +20,10 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * stopyear => integer last year that can be selected * timezone => float/string timezone * applydst => apply users daylight savings adjustment? + * optional => if true, show a checkbox beside the date to turn it on (or off) */ var $_options = array('startyear'=>1970, 'stopyear'=>2020, - 'timezone'=>99, 'applydst'=>true); + 'timezone'=>99, 'applydst'=>true, 'optional'=>false); /** * These complement separators, they are appended to the resultant HTML @@ -78,6 +79,10 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group $this->_elements[] =& MoodleQuickForm::createElement('select', 'day', null, $days, $this->getAttributes(), true); $this->_elements[] =& MoodleQuickForm::createElement('select', 'month', null, $months, $this->getAttributes(), true); $this->_elements[] =& MoodleQuickForm::createElement('select', 'year', null, $years, $this->getAttributes(), true); + // If optional we add a checkbox (no text) which the user can use to turn if on + if($this->_options['optional']) { + $this->_elements[] =& MoodleQuickForm::createElement('checkbox','on', null, get_string('enable'), $this->getAttributes(), true); + } $this->setValue(); } @@ -87,6 +92,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group function setValue($value=0) { + $requestvalue=$value; if (!($value)) { $value = time(); } @@ -96,7 +102,10 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group 'day' => $currentdate['mday'], 'month' => $currentdate['mon'], 'year' => $currentdate['year']); - + // If optional, default to off, unless a date was provided + if($this->_options['optional']) { + $value['on'] = $requestvalue ? true : false; + } } parent::setValue($value); } @@ -150,6 +159,13 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group } } if (count($valuearray)){ + if($this->_options['optional']) { + // If checkbox is not on, the value is zero, so go no further + if(empty($valuearray['on'])) { + $value[$this->getName()]=0; + return $value; + } + } $value[$this->getName()]=make_timestamp($valuearray['year'], $valuearray['month'], $valuearray['day'], diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 0551e93e95..e0f229d814 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -334,7 +334,8 @@ form.mform .fitemtitle { margin: 5px 0 0 10px; text-align: right; } -div.fitem fieldset.fgroup label, div.fradio label, div.fcheckbox label{ +div.fitem fieldset.fgroup label, div.fradio label, div.fcheckbox label, +fieldset.fdate_selector label { display:inline; float: none; width: auto;