简体   繁体   English

如何在PlayFramework中将日期值传递给@inputText

[英]how to pass date value to @inputText in PlayFramework

I want to create a form where by default when form is loaded it will set current date in format "dd.MM.yyyy" I tried to insert it via value in @inputText but it is not working: 我想创建一个表单,默认情况下,在加载表单时它将以“ dd.MM.yyyy”格式设置当前日期。我试图通过@inputText中的值插入它,但它不起作用:

@inputText(
                postForm("postedAt"),
                'value->(new Date().format("dd.mm.yyyy")) ,
                'type->"date",
                '_label->"Date",
                '_showConstraints->false,
                'class -> "form-control",
                'required -> "required")

Still input value is not showing current date: 仍然输入值未显示当前日期:

http://i.stack.imgur.com/IWaZP.png

Any idea how to pass the data display it in @inputText ? 任何想法如何传递数据显示在@inputText吗?

How about using a date field as documented here ? 如何使用此处记录的date字段? For ex. 对于前。 in your form definition, you could bind the postedAt field as: 在表单定义中,您可以将postedAt字段绑定为:

Form( ...
  "postedAt" -> date("dd.MM.yyyy")
  ...
)

Then fill the postedAt field in the form with new Date() in your Action and then, in your template, display its value like 然后填写postedAt领域与形式, new Date()在你的Action ,然后在你的模板,显示像它的价值

@inputText(postForm("postedAt"),
   'type -> "date",
   '_label -> "Date",
   '_showConstraints -> false,
   'class -> "form-control",
   'required -> "required")

I haven't tested this code, but it should work as advertised. 我没有测试过此代码,但它应该如广告所示那样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM