Symfony3 twig datepicker gives 'This value is not valid' , after submit

210 views Asked by At

In my controller I'm getting the date from the URL :

 $Birthdate=$request->get('datebirth');

and in my twig I'm creating datapicker and I have a default value from the controller.

Here is my twig:

 {{ form_row(formPatient.patBirthDate,{'value' : datebirth|date('d-m-y') },{ 
 'attr': {'class': 'datepicker-date'}}) }}
1

There are 1 answers

0
Fabian Schmick On

Your date format is wrong. For the HTML5 date type field it has to be the following format Y-m-d:

So in your case:

datebirth|date('Y-m-d')

And if this should not work, try to change the format on your formbuilder like this, too:

$builder->add('patBirthDate', DateType::class, array(
        'widget' => 'single_text',
        'format' => 'yyyy-MM-dd'
    )
)

Read more about it in the docs: https://symfony.com/doc/current/reference/forms/types/date.html