Custom validation of Play 2.0 form (scala) -
i'm writing little hobby app. now, in application want people have userid (just mine niklassaers here on stack overflow), , if taken, want user error can select another.
here follows signup object, gives me error @ line "mapping(": "missing arguments method mapping in object forms; follow method `_' if want treat partially applied function"
object signup extends controller { val userform: form[userprofile] = form( mapping( "userid" -> nonemptytext, "passwordhash" -> nonemptytext, "email" -> email ) verifying ( "thisisatest", { case(userid, passwordhash, email) => true } // "userid taken", { dbservice.exists(userprofile.getclass().getname(), userid) } )(userprofile.apply)(userprofile.unapply)) def index = action { ok(views.html.signup(userform)) } def register = action { implicit request => userform.bindfromrequest.fold( errors => badrequest(views.html.signup(errors)), user => redirect(routes.profile.index)) } } as can see, i've replaced lookup service test verification returns true, make example less complex. completeness, userdetail case class:
case class userprofile( userid : string, email: string, passwordhash: string) i'm scala newbie , play newbie, i'm sorry if trivial question. but:
what doing wrong since error?
is right way of adding own validation?
follow-up question: redirect if goes well, how should redirect page referencing verified form?
cheers
nik
finally got around this: verifying isn't comes after mapping, comes @ constraint. should be
"userid" -> nonemptytext.verifying( "userid taken", userid => dbservice.exists(userprofile.getclass().getname().replace("$", ""), userid) == false ), i hope helps others have same problem :-)
Comments
Post a Comment