如何在Play中获取DateTime输入! CRUD表格? [英] How to get a DateTime input in a Play! CRUD form?
问题描述
默认情况下,一个 java.util.Date
字段在CRUD表单中以简单的DATE输入表示。
public class DatedModel extends Model {
public Date creationDate;在CRUD管理员中,
我看到:
creationDate [TEXTINPUT]
yyyy-MM-dd格式。
有没有办法使用DateTime输入,而不是选择 字段只有(不是全部修改application.conf date.format
)?
有没有办法影响在自动化CRUD管理员中,哪个小部件用于给定的字段?
我终于在文档中找到了我的答案:
你可以确实自定义每个字段;使用 jquery在lunatech博客上可以找到更广泛的例子数据表也显示如何修改分页。
#{crud.table fields:['name','公司']}
#{crud.custom'company'}
< a href =@ {Companies.show(object.company.id)}>
$ {object.company.name}
< / a>
#{/ crud.custom}
#{/ crud.table}
PS。
@AditSaxena提示很好,确实是一个简单的解决方案;但不是我想要的,因为提示不正确是不能接受的!对于一个用户来说明显令人困惑
所以对于datetime输入(具体问题),我们可以组合注释(在 doc )
@As(lang = {*},value = {yyyy-MM-dd hh:mm:ss})
pre>
带有自定义提示,例如。
#{crud .custom'mydate'}
< span class =crudHelp>
日期格式:etcetc。
< / span>
...
#{/ crud.custom}
还要指出,您可以编写自己的验证器
其他相关有用的问题:
- 可以在playframework中覆盖CRUD控制器中的默认保存操作,然后重定向到列表
- 播放!框架CRUD模块:添加默认值并更改日期格式?
- 播放框架CRUD文件上传关于自定义文件上传字段
By default a java.util.Date
field is represented in a CRUD form as a simple "DATE" input.
public class DatedModel extends Model {
public Date creationDate;
in the CRUD admin I see:
creationDate [TEXTINPUT]
yyyy-MM-dd format.
Is there any way to have a DateTime input instead, on selected fields only (not all of them modifying the application.conf date.format
)?
Is there a way to affect which "widget" is used for a given field in the 'automated' CRUD admin?
I finally found in the documentation my answer:
You can indeed customize each field; a more extensive example can be found on the lunatech blog using jquery datatables which also shows how to modify pagination.
#{crud.table fields:['name', 'company']}
#{crud.custom 'company'}
<a href="@{Companies.show(object.company.id)}">
${object.company.name}
</a>
#{/crud.custom}
#{/crud.table}
PS.
@AditSaxena hint was good and indeed a simple solution; but not what I wanted because it's not acceptable that the 'hint' is not correct! Clearly confusing for a user!
So for a datetime input (the specific question) we can combine the annotation (described in the doc)
@As(lang={"*"}, value={"yyyy-MM-dd hh:mm:ss"})
with a custom hint, eg.
#{crud.custom 'mydate'}
<span class="crudHelp">
Date format: etcetc.
</span>
...
#{/crud.custom}
I'll also point out that you can write your own validator
Other related useful questions:
- Is it possible in playframework to override the default save action in the CRUD controller and redirect to list after
- Play! framework CRUD module: adding default values and change date format?
- Play framework CRUD file upload about custom file upload fields
这篇关于如何在Play中获取DateTime输入! CRUD表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!