简体   繁体   中英

"Enabled from" on a new Sonata Page Bundle site is invalid

I have a brand-new installation of Sonata Page Bundle. I am creating a Site entity using the Site admin screen.

I use the DateTimePicker that comes with the bundle to choose the "enabled from" date. The picker creates this date: May 27, 2021, 6:40:43 pm

I then save the page. The validator tells me that "This value is not valid." On a string that the same page's picker generated!

Is this a known bug? Or am I doing something wrong? I would just leave this blank, but the field is mandatory.

For reference, composer says I have page-bundle version 3.22.2, which packagist says is the newest stable version. The version for admin-bundle is 3.100.2.

Also for reference: My Firefox browser is set to use American English as its language, in case that's relevant.

I installed a symfony (v4.4.25) + sonata project with PHP 7.4.2 to reproduce this and I didn't have this error, my browser is in english too.

在此处输入图像描述

在此处输入图像描述

You should verify if you have moment.min.js or any javascript missing. The javascript should change the date format to a database friendly format, mysql for me, on submit event.

在此处输入图像描述

After installing the sonata bundles with the recipes (to avoid doing all the configuration manually), I added to sonata_admin.yaml

   assets:
        extra_javascripts:
            - bundles/sonatapage/sonata-page.back.min.js
        extra_stylesheets:
            - bundles/sonatapage/sonata-page.back.min.css

I had the following error on /admin/app/sonatapagesite/1/edit

Too few arguments to function Sonata\Form\Type\BasePickerType::__construct(), 0 passed in /Users/hyper/Work/Stackoverflow/so/vendor/symfony/form/FormRegistry.php on line 91 and exactly 3 expected

To fix it, I added to bundles.php

Sonata\Form\Bridge\Symfony\SonataFormBundle::class => ['all' => true],

It looks like the validator is doing something wrong, as it expects a different format (probably yyyy-mm-dd).

I found an answer made by @Capfer to a similar question that may be useful. He basically changes the expected date format of the form type.

Link

$formMapper
->add('dateOfAdoption', 'sonata_type_datetime_picker',
     [
        'dp_default_date' => $container->getCreatedAt()->format('d M. Y H:i '),
        'datepicker_use_button' => true,
        'mapped' => false,
     ]
);

Note: 
d - The day of the month (from 01 to 31)
M - A short textual representation of a month (three letters)
Y - A four digit representation of a year
H - 24-hour format of an hour (00 to 23)
i - Minutes with leading zeros (00 to 59)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM