Skip to content

Commit

Permalink
Merge pull request #158 from andrej-griniuk/feature/handle-time-fields
Browse files Browse the repository at this point in the history
Handle Time fields in DateTimeWidget
  • Loading branch information
ADmad authored Mar 30, 2017
2 parents c9ab4ff + e7dbf50 commit 26267bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Menu/MenuDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class MenuDropdown
**/
protected $title;


/**
* Array of MenuDivider|MenuItem entries
*
Expand Down
22 changes: 19 additions & 3 deletions src/View/Widget/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public function render(array $data, ContextInterface $context)
}

if (!($val instanceof DateTimeInterface) && !empty($val)) {
$val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
if ($type === 'date') {
$val = Time::parseDate($val);
} elseif ($type === 'time') {
$val = Time::parseTime($val);
} else {
$val = Time::parseDateTime($val);
}
}

if ($val) {
Expand All @@ -54,9 +60,19 @@ public function render(array $data, ContextInterface $context)
}

if (!$format) {
$format = $type === 'date' ? 'L' : 'L LT';
if ($type === 'date') {
$format = 'L';
} elseif ($type === 'time') {
$format = 'LT';
} else {
$format = 'L LT';
}
}

$icon = $type === 'time'
? 'time'
: 'calendar';

$widget = <<<html
<div class="input-group $type">
<input
Expand All @@ -80,7 +96,7 @@ class="form-control"
$disabled
/>
<label for="$id" class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
<span class="glyphicon glyphicon-$icon"></span>
</label>
</div>
html;
Expand Down

0 comments on commit 26267bf

Please sign in to comment.