本文介绍了Symfony2中的jQuery datepicker给出“此值无效".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以symfony2形式添加了jQuery datepicker.

I added a jQuery datepicker in my symfony2 form.

细枝文件:

$('.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')
        ));

我尝试了几种日期格式.但是我提交时总是得到This value is not valid..我试图获取表格错误,但没有提供更多信息.

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.

推荐答案

尝试类似的方法

$('.date').datepicker({ 
    showOn: 'button', 
    buttonImageOnly: true, 
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd-mm-yy',
    yearRange: "-0:+1"  
});

PostType.php

PostType.php

$builder->add('toDate','date',array(
    'widget' => 'single_text',
    'format' => 'dd-MM-yyyy',
    'attr' => array('class' => 'date')
 ))

这篇关于Symfony2中的jQuery datepicker给出“此值无效".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:22