Play フレームワーク 2.1.1 と scala を使用してサインアップ フォームを検証しようとしています。私は得た
コンパイル エラー:型が一致しません。見つかった: (文字列、文字列、文字列、文字列、文字列、文字列、文字列、Int) => models.Contact が必要: (文字列、文字列、文字列、文字列、文字列、(文字列、文字列)、文字列、Int) => ?
models.scala :
package models
case class Contact(firstname: String, lastname: String, jobtitle: String, phone:String, email: String, password: String, companyname: String, employeescount: Int)
Application.scala :
val contactForm = Form(
mapping(
"firstname" -> nonEmptyText(minLength=2, maxLength=10),
"lastname" -> nonEmptyText(minLength=2, maxLength=10),
"jobtitle" -> nonEmptyText(minLength=2, maxLength=10),
"phone" -> nonEmptyText(minLength=2, maxLength=10),
"email" -> (email verifying nonEmpty),
"password" -> tuple(
"main" -> text(minLength = 6),
"confirm" -> text
).verifying(
// Add an additional constraint: both passwords must match
"Passwords don't match", { case (p1, p2) => p1 == p2 }
).transform({case (p, _) => p}, {p => p -> p}),
"companyname" -> nonEmptyText,
"employeescount" -> number
)(Contact.apply)(Contact.unapply)
)
index.scala.html
@form(routes.Application.save()) {
@text(contactForm("firstname"), '_label -> "First Name : ", 'toto -> "titi")
@text(contactForm("lastname"), '_label -> "Last Name : ", 'toto -> "titi")
@text(contactForm("jobtitle"), '_label -> "Job Title : ", 'toto -> "titi")
@text(contactForm("phone"), '_label -> "Phone : ", 'toto -> "titi")
@text(contactForm("email"), '_label -> "Email : ")
@password(contactForm("password.main"), '_label -> "Password : ")
@password(contactForm("password.confirm"), '_label -> "Confirm Password : ")
@text(contactForm("companyname"), '_label -> "Company Name : ", 'toto -> "titi")
@select(
contactForm("employeescount"),
options(
"0" -> "0-10",
"1" -> "10-100",
"2" -> "100-1000",
"2" -> " > 1000"
),
'_label -> "Employees"
)
<input type="submit" value="Submit">
}