Skip to content

DateTimeType widget single_text #27

Description

@andrelec1
   $builder
            ->add('date', DateTimeType::class, [
                'widget' => 'single_text',
            ])
        ;

result => Could not find a transformer for any of these types (datetime, form)

Actualy a bypass by using a simple text input and appy a transformer on it :

->addModelTransformer(new CallbackTransformer(
                function ($datetimeObj) {
                    if ($datetimeObj === null) {
                        return '';
                    }
                    return $datetimeObj->format('Y-m-d H:i:s');
                },
                function ($datetimeString) {
                    return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datetimeString, new \DateTimeZone('UTC'));
                }
            ))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions