在scala中播放框架表单验证

时间:2013-05-14 09:45:00

标签: scala playframework

在scala中使用play框架表单验证 跟随我的注册对象,它在“映射(”:“缺失”一行给我一个错误 对象Forms中方法映射的参数;如果你愿意,可以用'_'跟随这个方法 将其视为部分应用的功能“

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)
)

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:2)

使用对整个“表单支持对象”的验证不允许您向表单中的各个字段添加错误。如果您想这样做,请参阅Play! framework 2.0: Validate field in forms using other fields

相关问题