Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeType widget single_text #27

Open
andrelec1 opened this issue Nov 28, 2020 · 0 comments
Open

DateTimeType widget single_text #27

andrelec1 opened this issue Nov 28, 2020 · 0 comments

Comments

@andrelec1
Copy link

andrelec1 commented Nov 28, 2020

   $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'));
                }
            ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant