我正在尝试使用 PlayFramework 日期映射和 datetime-local 字段。 Docs Here
截断的映射看起来像这样,我为验证器尝试了几个选项。
mapping(
"startTimeGt" -> optional(jodaDate),
"startTimeLt" -> optional(jodaDate("dd-MM-yyyy HH:mm"))
)(...
我已经尝试了捆绑的 inputDate 助手和 datetime-local 字段。
但无论我尝试什么组合,我都会得到
error.date
在表单提交上。我觉得这应该很简单,或者我在文档中遗漏了一些东西,或者他们只是不告诉我。有没有人得到所需 html 的工作示例和 jodaDate
映射?
最佳答案
我猜 formWithErrors 是由代码引起的
"startTimeLt" -> optional(jodaDate("dd-MM-yyyy HH:mm"))// the format maybe wrong
因为你不知道 jodaDate 从前端传递到后端的格式。您可以在从请求中绑定(bind)表单之前打印表单内容,如下所示
def index() { implicit request =>
println(request)//it will print the request content and you can find the "startTimeLt" to verify its format
form.bindFromRequest.fold...
}
祝你好运
关于scala - Play 2.5 中 jodaDate 映射的可接受格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613218/