In an Entity class I defined a property like
use Symfony\Component\Validator\Constraints as Assert;
class MyEntity
{
...
/**
* @Assert\Date()
*/
protected $date_of_birth;
...
}
In the FormType class I use the property:
$builder
->add('date_of_birth',
DateType::class,
array(
'label' => 'Birthday',
'required' => true,
'translation_domain' => 'messages',
'widget' => 'single_text',
'html5' => false,
'data' => null,
'format' => $this->container->getParameter('date.format.icu'),
'attr' => array( 'class' => 'js-bootstrap-datepicker', 'placeholder' => 'DD.MM.YYYY' ),
)
)
;
In the template I output the form suppressing browser side validation:
...
{{ form_start(form_a, {'attr': {'novalidate': 'novalidate'}}) }}
...
{{ form_label(form_a.date_of_birth) }}*
{{ form_errors(form_a.date_of_birth) }}
{{ form_widget(form_a.date_of_birth) }}
...
Unfortunately it doesn't really matter what I type into the date field. I can leave it empty - it still is OK for the validator. The NotBlank Constraint works though. I suppose I am missing something specific in the Date Constraint usage?