Skip to content

Commit

Permalink
handle Time fields in DateTimeWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
andrej-griniuk committed Mar 10, 2017
1 parent c9ab4ff commit 8156c05
Showing 1 changed file with 19 additions and 3 deletions.
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 8156c05

Please sign in to comment.