DatePicker.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Form element to select a date and hour (with popup datepicker)
  5. */
  6. class DatePicker extends HTML_QuickForm_text
  7. {
  8. /**
  9. * Constructor
  10. */
  11. public function DatePicker($elementName = null, $elementLabel = null, $attributes = null)
  12. {
  13. if (!isset($attributes['id'])) {
  14. $attributes['id'] = $elementName;
  15. }
  16. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  17. $this->_appendName = true;
  18. $this->_type = 'date_picker';
  19. }
  20. /**
  21. * HTML code to display this datepicker
  22. */
  23. public function toHtml()
  24. {
  25. $js = $this->getElementJS();
  26. return $js.parent::toHtml();
  27. }
  28. function setValue($value)
  29. {
  30. $value = substr($value, 0, 16);
  31. $this->updateAttributes(
  32. array(
  33. 'value' => $value
  34. )
  35. );
  36. }
  37. /**
  38. * Get the necessary javascript for this datepicker
  39. */
  40. private function getElementJS()
  41. {
  42. $js = null;
  43. $id = $this->getAttribute('id');
  44. $js .= "<script>
  45. $(function() {
  46. $('#$id').datepicker({
  47. dateFormat: 'yy-mm-dd'
  48. });
  49. });
  50. </script>";
  51. return $js;
  52. }
  53. }