【问题标题】:play framework form validation in scala在scala中播放框架表单验证
【发布时间】:2013-05-14 09:45:00
【问题描述】:

在 scala 中播放框架表单验证的工作 跟随我的注册对象,它在“映射(”:“缺少 对象形式中方法映射的参数;如果您愿意,请使用 `_' 遵循此方法 把它当作一个部分应用的函数”

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

【问题讨论】:

    标签: scala playframework


    【解决方案1】:
    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)

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-16
        • 2014-07-29
        • 1970-01-01
        • 1970-01-01
        • 2014-05-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多