Reputation: 5392
Here is a snippet of the template file:
@helper.form(routes.Signup.signupCont) {
@helper.inputText(signupForm("teamname"))
<div class="row">
<div class="span2"><label class="label_form_email_signup">Team name</label></div>
<div class="span4"><input id="Signup_teamname" type="text" class="span4 input" maxlength="24" name="teamname"></div>
</div>
}
The form definition:
def signupForm = Form(
mapping(
"teamname" -> text(minLength = 4, maxLength = 30).verifying(
"Name already in use.", teamname => Team.findByNameStrict(teamname).isEmpty),
"email" -> email.verifying(
"Email already in use.", email => Team.findByEmail(email).isEmpty).verifying(
"University email required", email => email.matches(""".*\.ac\.uk""")),
"password" -> tuple(
"main" -> text(minLength = 6),
"confirm" -> text).verifying(
"Passwords do not match.", password => password._1 == password._2))((teamname, email, password) =>
(teamname, email, password._1))(data => Some(data._1, data._2, ("",""))))
When using a wrong email and submitting the form, for example, the page reloads, yet the form fields are empty (so the deconstructor fails) and there is no error message next to the email box. How does one implement this behavior?
Upvotes: 2
Views: 1075
Reputation: 1403
Make sure you're passing the form with the errors to your view when rendering it back. For example:
signUpForm.bindFromRequest.fold (
errors => {
/// assuming the page is signUp
BadRequest(views.html.signUp(errors))
},
info => {
// all ok, process the form
}
)
Upvotes: 1