Skip to content

[Form] Date\TimeType marked as invalid on request with single_text and zero seconds #20304

Closed
@LuisDeimos

Description

@LuisDeimos

When using a form with an Time type with option 'widget' => 'single_text', and 0 is selected in the seconds, we obtain an TransformationFailedException "Unable to reverse value for property path "[time]": Data missing".

This, because some browsers omit seconds if the value of 0 is selected, so if the value selected in the field is, for example, '01:05:00 ', the request is sent as '01:05' (check this chromium issue).

An unit test:

    public function testSubmitWithSecondsAndBrowserOmissionSeconds()
    {
        $form = $this->factory->create('datetime', null, array(
            'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'date_widget' => 'choice',
            'years' => array(2010),
            'time_widget' => 'single_text',
            'input' => 'datetime',
            'with_seconds' => true,
        ));

        $form->setData(new \DateTime());

        $input = array(
            'date' => array(
                'day' => '2',
                'month' => '6',
                'year' => '2010',
            ),
            'time' => '03:04'
        );

        $form->submit($input);

        $this->assertDateTimeEquals(new \DateTime('2010-06-02 03:04:00 UTC'), $form->getData());
    }

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