Closed
Description
Symfony version(s) affected
6.0.0 - 6.0.8
Description
Hello folks!
When creating a TimeType
form field with the widget
as single_text
and timezones the displayed value is not properly formatted for the browser.
$fakeEntity = new \stdClass();
$fakeEntity->time = new \DateTime();
// Create the form field
->add('time', TimeType::class, [
'html5' => true,
'widget' => 'single_text',
'view_timezone' => 'Europe/Paris',
'model_timezone' => 'UTC',
'reference_date' => new \DateTime('now', new \DateTimeZone('UTC')),
])
is outputting in HTML:
<input type="time" id="form_time" name="form[time]" required="required" class="shadow-sm focus:ring-blue focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md" value="2022-04-21 14:49">
How to reproduce
$fakeEntity = new \stdClass();
$fakeEntity->time = new \DateTime();
// Create the form field
->add('time', TimeType::class, [
'html5' => true,
'widget' => 'single_text',
'view_timezone' => 'Europe/Paris',
'model_timezone' => 'UTC',
'reference_date' => new \DateTime('now', new \DateTimeZone('UTC')),
])
is outputting in HTML:
<input type="time" id="form_time" name="form[time]" required="required" class="" value="2022-04-21 14:49">
Possible Solution
My guess is here: form/Extension/Core/Type/TimeType.php:84
We are dealing with the reference_date
on the PRE_SUBMIT
event but it's maybe too soon? The date shouldn't be displayed yet with the option HTML5
enabled.
Additional Context
Here a result from my project with the reproduced step.
And the result if I remove the date from the
value
field.
And the result if I set
HTML5
to false.
Many thanks & best regards 😊