Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
on error data is no longer frozendate/time
  • Loading branch information
highstrike committed Sep 23, 2016
1 parent 8daeac5 commit 7da6699
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/View/Widget/DTPickerWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Cake\View\Widget\WidgetInterface;
use Cake\View\Form\ContextInterface;
use Cake\Utility\Text;
use Cake\I18n\FrozenTime;
use Cake\I18n\FrozenDate;
use Cake\Utility\Text;

/**
* DTPicker
Expand All @@ -20,7 +20,7 @@
* echo $this->Form->input('date3', ['type' => 'dtpicker', 'mode' => 'time']);
*
* @author Flavius
* @version 0.1
* @version 0.2
*/
class DTPickerWidget implements WidgetInterface
{
Expand Down Expand Up @@ -72,23 +72,25 @@ public function render(array $data, ContextInterface $context) {
$data['class'] = $data['type'];
unset($data['val'], $data['mode']);

// transform into frozen time if not already
if(!($data['value'] instanceof FrozenTime || $data['value'] instanceof FrozenDate))
$data['value'] = new FrozenTime($data['value']);

// transform values
if($data['value'] instanceof FrozenTime || $data['value'] instanceof FrozenDate) {
if($mode == 'datetime') {
$hval = $data['value']->format('Y-m-d H:i:s');
$data['value'] = $data['value']->format('d-M-Y H:i:s');
}
if($mode == 'date') {
$hval = $data['value']->format('Y-m-d');
$data['value'] = $data['value']->format('d-M-Y');
}
if($mode == 'time')
$hval = $data['value'] = $data['value']->format('H:i:s');
if($mode == 'datetime') {
$hval = $data['value']->format('Y-m-d H:i:s');
$data['value'] = $data['value']->format('d-M-Y H:i:s');
}
if($mode == 'date') {
$hval = $data['value']->format('Y-m-d');
$data['value'] = $data['value']->format('d-M-Y');
}
if($mode == 'time')
$hval = $data['value'] = $data['value']->format('H:i:s');

// render
$rand = Text::uuid();
return "<div id='{$rand}'>" . $this->_templates->format('input', [
return "<div id='{$rand}' style='position: relative;'>" . $this->_templates->format('input', [
'name' => $data['name'],
'type' => 'hidden',
'attrs' => $this->_templates->formatAttributes(['value' => $hval]),
Expand Down

0 comments on commit 7da6699

Please sign in to comment.