3

scala 中的播放框架表单验证的工作遵循我的 Signup 对象,它在“mapping(”:“缺少对象表单中的方法映射的参数;如果你想将其视为此方法,请使用“_”)部分应用函数"

case class UserRegistration(username: String, password1: String, password2: String)

val loginForm = Form(
 mapping(
   "username" -> email,
   "password1" -> text,
   "password2" -> text
 )
 (UserRegistration.apply)(UserRegistration.unapply)
 verifying ("Passwords must match",  => f.password1 == f.password2)
)
4

2 回答 2

6
case class UserRegistration(username: String, password1: String, password2: String)

val loginForm = Form(
  mapping(
    "username" -> email,
    "password1" -> text,
    "password2" -> text
  )
  (UserRegistration.apply)(UserRegistration.unapply)
  verifying ("Passwords must match", f => f.password1 == f.password2)
)

你错过了("Passwords must match", f => f.password1 == f.password2)

于 2013-05-14T09:46:17.840 回答
2

在整个“表单支持对象”上使用验证不会让您将错误添加到表单中的各个字段。如果您想这样做,请参阅Play!框架 2.0:使用其他字段验证表单中的字段

于 2013-11-09T22:58:23.303 回答