Symfony 2.0日期时间小部件;如何使用JQuery UI日期选择器呈现? [英] Symfony 2.0 datetime widget; how to render with JQuery UI date picker?

查看:104
本文介绍了Symfony 2.0日期时间小部件;如何使用JQuery UI日期选择器呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Symfony 2.0应用程序.

I have a Symfony 2.0 app.

它在实体上有一个datetime字段,在表单上有一个datetime字段.

It has a datetime field on an entity, and a datetime field on a form.

如何使用jQuery UI日期选择器而不是3个选择框来显示表单的日期部分?

How can I have the date part of that form render with a jQuery UI date picker instead of the 3 select boxes?

谢谢

编辑

这是我到目前为止所拥有的:

This is what I have so far:

$builder->add('start_at', 'datetime',array('date_widget' => 'single_text'));

这会在页面上放置一个文本框作为日期,然后在时间上选择2个选择框,您可以轻松地在其上添加一个jQuery UI!

This puts a text box on the page for the date then 2 select boxes for the time, and you can easily add a jQuery UI on top of that!

问题是Symfony日期时间字段仅接受格式为"2012年8月29日"的输入.如果用户输入"2012年8月29日"或"2012年8月29日",则会拒绝验证.

The problem is the Symfony datetime field only accepts input in the format "Aug 29, 2012". If the user types in "Aug 29 2012" or "29 Aug 2012" it refuses to validate.

因此,凡能解决此问题或提出完全不同的工作方法的人,将不胜感激.

So anyone who can fix that problem or suggest an entirely different working approach would be much appreciated.

推荐答案

我最终使用了这段代码

    $builder->add('start_at', 'datetime' ,array(
            'date_widget'=> 'single_text',
            'date_format'=>'d/M/y',
            ....
        ));

然后将jQuery UI放在其顶部,并处理它仅接受一种格式的输入这一事实.

then putting jQuery UI on top of it, and just dealing with the fact that it only accepts input in one format only.

这篇关于Symfony 2.0日期时间小部件;如何使用JQuery UI日期选择器呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆