LiformBundle icon indicating copy to clipboard operation
LiformBundle copied to clipboard

DateTimeType widget single_text

Open andrelec1 opened this issue 5 years ago • 0 comments

   $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'));
                }
            ))

andrelec1 avatar Nov 28 '20 00:11 andrelec1