Skip to content

[Form] TimeType with a reference_date, view_timezone and model_timezone with a widget to single_text is not displaying correctly with HTML5 enabled. #46137

@RSickenberg

Description

@RSickenberg

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

image

Here a result from my project with the reproduced step.

image

And the result if I remove the date from the value field.

image

And the result if I set HTML5 to false.

Many thanks & best regards 😊

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy