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

◇◆丶佛笑我妖孽 提交于 2019-12-10 04:13:42

问题


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.


回答1:


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')
 ))



回答2:


Just to make it clear.

in jQuery UI:

mm = "01"
MM = "January"

in Symfony:

mm // is not valid format
MM == "01"

Symfony MM is same as jQuery UI mm



来源:https://stackoverflow.com/questions/19509378/jquery-datepicker-in-symfony2-gives-this-value-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!