123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Form element to select a date and hour (with popup datepicker)
- */
- class DatePicker extends HTML_QuickForm_text
- {
- /**
- * Constructor
- */
- public function DatePicker($elementName = null, $elementLabel = null, $attributes = null)
- {
- if (!isset($attributes['id'])) {
- $attributes['id'] = $elementName;
- }
- HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
- $this->_appendName = true;
- $this->_type = 'date_picker';
- }
- /**
- * HTML code to display this datepicker
- */
- public function toHtml()
- {
- $js = $this->getElementJS();
- return $js.parent::toHtml();
- }
- function setValue($value)
- {
- $value = substr($value, 0, 16);
- $this->updateAttributes(
- array(
- 'value' => $value
- )
- );
- }
- /**
- * Get the necessary javascript for this datepicker
- */
- private function getElementJS()
- {
- $js = null;
- $id = $this->getAttribute('id');
- $js .= "<script>
- $(function() {
- $('#$id').datepicker({
- dateFormat: 'yy-mm-dd'
- });
- });
- </script>";
- return $js;
- }
- }
|