Date.php 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. class Date extends Text
  4. {
  5. public static $js = [
  6. '@moment',
  7. '@bootstrap-datetimepicker',
  8. ];
  9. public static $css = [
  10. '@bootstrap-datetimepicker',
  11. ];
  12. protected $format = 'YYYY-MM-DD';
  13. public function format($format)
  14. {
  15. $this->format = $format;
  16. return $this;
  17. }
  18. protected function prepareInputValue($value)
  19. {
  20. if ($value === '') {
  21. $value = null;
  22. }
  23. return $value;
  24. }
  25. public function render()
  26. {
  27. $this->options['format'] = $this->format;
  28. $this->options['locale'] = config('app.locale');
  29. $this->options['allowInputToggle'] = true;
  30. $this->script = "$('{$this->getElementClassSelector()}').datetimepicker(".admin_javascript_json($this->options).');';
  31. $this->prepend('<i class="fa fa-calendar fa-fw"></i>')
  32. ->defaultAttribute('style', 'width: 200px;flex:none');
  33. return parent::render();
  34. }
  35. }