Play 2.0: Verifying two fields together (i.e. password and password confirmation)

489 views
Skip to first unread message

Lino Rosa

unread,
Dec 5, 2011, 6:35:25 PM12/5/11
to play-framework
Say I have this form:

val signupForm = Form(
of(NewUser)(
"email" -> of[String],
"password" -> of[String],
"confirmation" -> of[String],
"nickname" -> of[String]
)
)

Anybody has a clever solution to add a verify on the "password" field
to match "confirmation"? The easy way out would be to put it at the
bottom:

...
"nickname" -> of[String]
)
) verifying (
"Passwords do not match",
(user: NewUser) => user.password == user.confirmation
)

But that would mean the "password" field on the view wouldn't know
about its validation error. That's fine for some cases, but far from
ideal, I think.

Ideas?

Guillaume Bort

unread,
Dec 6, 2011, 5:00:32 AM12/6/11
to play-fr...@googlegroups.com
Currently it is not possible. But yes I agree, a validation constraint
should be able to produce errors on other fields.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort

danielkol

unread,
Dec 13, 2011, 2:22:30 PM12/13/11
to play-fr...@googlegroups.com
I was running into a similar challenge so I thought I'd use your solution in the interim, although I was having problems accessing the global errors.  In your above example, how do you access the non field bound errors for your signup form?

In my code I pass back a form to a view to process errors and have tried iterating over both someUserForm.errors and someUserForm.globalErrors with no luck.
Reply all
Reply to author
Forward
0 new messages