Limenius / LiformBundle

Symfony Bundle to render Symfony Forms to JSON Schema
MIT License
138 stars 44 forks source link

DateTimeType widget single_text #27

Open andrelec1 opened 4 years ago

andrelec1 commented 4 years ago
   $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'));
                }
            ))