I added a jQuery datepicker in my symfony2 form.
twig file:
$('.date').datepicker({
showOn: 'button',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-MM-dd ',
yearRange: "-0:+1"
});
PostType.php
$builder->add('toDate','datetime',array(
'input' => 'datetime',
'widget' => 'single_text',
'format' => 'yy-MM-dd',
'attr' => array('class' => 'date')
));
I tried several date formats. But I always get This value is not valid.
when I submit. I tried to get the form errors, but it doesn't give any more information.
try something like this
$('.date').datepicker({
showOn: 'button',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy',
yearRange: "-0:+1"
});
PostType.php
$builder->add('toDate','date',array(
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
'attr' => array('class' => 'date')
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With