0
val registrationForm: Form[Registration]=Form(
mapping(
"fname"->text(minLength=2),
"lname"->text(minLength=1),
"userEmail"->text(minLength=5),
"userPassword" -> tuple(
"main" -> text(minLength = 6),
"confirm" -> text
).verifying(
// Add an additional constraint: both passwords must match
"Passwords don't match", userPassword => userPassword._1 == userPassword._2
),
"gender"->number,
"year"->number, 
"month"->number, 
"day"->number
)
{
// Binding: Create a User from the mapping result (ignore the second password and the 
accept field)
(fname, lname, userEmail, userPassword, gender, year, month, day, _) => 
Registration(fname,lname,userEmail,userPassword._1, gender, year,month,day)//error here
} 
{
// Unbinding: Create the mapping values from an existing User value
user => Some(user.fname, user.lname, user.userEmail,(user.userPassword, ""),
user.gender, user.year, user.month, user.day, false)
}

)//end registrationForm

我的案例课程是-

case class Registration(fname:String, lname:String, userEmail:String,
userPassword:String, gender:Int, year:Int,month:Int, day:Int )

上面的代码给出了错误的参数数量;预期 = 8。我已对发生错误的行发表评论

4

1 回答 1

1

您需要_在绑定表单时删除。

// Binding: Create a User from the mapping result 
//   (ignore the second password and the accept field)

(fname, lname, userEmail, userPassword, gender, year, month, day) =>
Registration(fname, lname, userEmail, userPassword._1, gender, year, month, day)

此外,您可能不想在取消绑定表单时输入密码。

// Unbinding: Create the mapping values from an existing User value

user => Some(user.fname, user.lname, user.userEmail, ("", ""),
            user.gender, user.year, user.month, user.day)
于 2013-09-29T07:32:03.107 回答