Skip to content

Commit

Permalink
MDL-39187 forms: fixed issue where calendar pop-up did not display wh…
Browse files Browse the repository at this point in the history
…en a date selector form element was added to a group
  • Loading branch information
mdjnelson committed May 3, 2013
1 parent 95190fd commit 34f9862
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
26 changes: 24 additions & 2 deletions lib/form/dateselector.php
Expand Up @@ -55,9 +55,18 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
protected $_options = array('startyear' => 1970, 'stopyear' => 2020, protected $_options = array('startyear' => 1970, 'stopyear' => 2020,
'timezone' => 99, 'optional' => false); 'timezone' => 99, 'optional' => false);


/** @var array These complement separators, they are appended to the resultant HTML */ /**
* @var array These complement separators, they are appended to the resultant HTML.
*/
protected $_wrap = array('', ''); protected $_wrap = array('', '');


/**
* @var null|bool Keeps track of whether the date selector was initialised using createElement
* or addElement. If true, createElement was used signifying the element has been
* added to a group - see MDL-39187.
*/
protected $_usedcreateelement = true;

/** /**
* constructor * constructor
* *
Expand Down Expand Up @@ -177,6 +186,10 @@ function onQuickFormEvent($event, $arg, &$caller)
} }
return parent::onQuickFormEvent($event, $arg, $caller); return parent::onQuickFormEvent($event, $arg, $caller);
break; break;
case 'addElement':
$this->_usedcreateelement = false;
return parent::onQuickFormEvent($event, $arg, $caller);
break;
default: default:
return parent::onQuickFormEvent($event, $arg, $caller); return parent::onQuickFormEvent($event, $arg, $caller);
} }
Expand All @@ -193,7 +206,16 @@ function toHtml()
$renderer = new HTML_QuickForm_Renderer_Default(); $renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}'); $renderer->setElementTemplate('{element}');
parent::accept($renderer); parent::accept($renderer);
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
$html = $this->_wrap[0];
if ($this->_usedcreateelement) {
$html .= html_writer::tag('span', $renderer->toHtml(), array('class' => 'fdate_selector'));
} else {
$html .= $renderer->toHtml();
}
$html .= $this->_wrap[1];

return $html;
} }


/** /**
Expand Down
28 changes: 25 additions & 3 deletions lib/form/datetimeselector.php
Expand Up @@ -56,8 +56,17 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
var $_options = array('startyear' => 1970, 'stopyear' => 2020, 'defaulttime' => 0, var $_options = array('startyear' => 1970, 'stopyear' => 2020, 'defaulttime' => 0,
'timezone' => 99, 'step' => 5, 'optional' => false); 'timezone' => 99, 'step' => 5, 'optional' => false);


/** @var array These complement separators, they are appended to the resultant HTML */ /**
var $_wrap = array('', ''); * @var array These complement separators, they are appended to the resultant HTML.
*/
protected $_wrap = array('', '');

/**
* @var null|bool Keeps track of whether the date selector was initialised using createElement
* or addElement. If true, createElement was used signifying the element has been
* added to a group - see MDL-39187.
*/
protected $_usedcreateelement = true;


/** /**
* Class constructor * Class constructor
Expand Down Expand Up @@ -196,6 +205,10 @@ function onQuickFormEvent($event, $arg, &$caller)
} }
return parent::onQuickFormEvent($event, $arg, $caller); return parent::onQuickFormEvent($event, $arg, $caller);
break; break;
case 'addElement':
$this->_usedcreateelement = false;
return parent::onQuickFormEvent($event, $arg, $caller);
break;
default: default:
return parent::onQuickFormEvent($event, $arg, $caller); return parent::onQuickFormEvent($event, $arg, $caller);
} }
Expand All @@ -212,7 +225,16 @@ function toHtml()
$renderer = new HTML_QuickForm_Renderer_Default(); $renderer = new HTML_QuickForm_Renderer_Default();
$renderer->setElementTemplate('{element}'); $renderer->setElementTemplate('{element}');
parent::accept($renderer); parent::accept($renderer);
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
$html = $this->_wrap[0];
if ($this->_usedcreateelement) {
$html .= html_writer::tag('span', $renderer->toHtml(), array('class' => 'fdate_time_selector'));
} else {
$html .= $renderer->toHtml();
}
$html .= $this->_wrap[1];

return $html;
} }


/** /**
Expand Down
4 changes: 2 additions & 2 deletions lib/form/yui/dateselector/dateselector.js
Expand Up @@ -189,11 +189,11 @@ YUI.add('moodle-form-dateselector', function(Y) {
if (this.panel === null) { if (this.panel === null) {
this.initPanel(config); this.initPanel(config);
} }
Y.all('fieldset.fdate_time_selector').each(function(){ Y.all('.fdate_time_selector').each(function() {
config.node = this; config.node = this;
new CALENDAR(config); new CALENDAR(config);
}); });
Y.all('fieldset.fdate_selector').each(function(){ Y.all('.fdate_selector').each(function() {
config.node = this; config.node = this;
new CALENDAR(config); new CALENDAR(config);
}); });
Expand Down

0 comments on commit 34f9862

Please sign in to comment.