Symfony2: checking date using form validator returns error

I added an element to my form, which is of type 'date', then it has a validation rule that indicates that the value of the form element must have a type date, otherwise return an error. However, instead of processing the check, Symfony returns an exception. See the following code:

UserType.php

$builder->add('startdate', 'date', array( 'label' => 'Start Date', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd') ); 

Validation.yml

 Acme\StoreBundle\Entity\User: properties: startdate: - Date: message: You must specify a valid release date 

Then, when I type '2001-01-aaa', hoping Symfony sees that the value is not in the correct format and handles the error as indicated, I get this instead

 Failed to match value '2007-01-aaa' with pattern 'yyyy-MM-dd' 500 Internal Server Error - InvalidArgumentException 

Am I doing something wrong here?

Thank you in advance

+4
source share
1 answer

This is mistake. Now fixed and merged into branch 2.0 . This, I hope, will be included in the next minor version.

+1
source

Source: https://habr.com/ru/post/1380620/


All Articles