Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datepicker in Symfony2 gives 'This value is not valid.'

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.

like image 375
Aris Avatar asked Oct 22 '13 05:10

Aris


1 Answers

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')
 ))
like image 77
rajesh kakawat Avatar answered Oct 21 '22 00:10

rajesh kakawat