I have a form for logging:
val loginForm = Form(tuple(
"email" -> (nonEmptyText verifying email.constraints.head),
"password" -> nonEmptyText
)
.verifying("Email doesn't exist", params => User.findByEmail(params._1) != None)
.verifying("Password incorrect", params =>
User.findByEmail(params._1).map(_.checkPassword(params._2)) == Some(true))
)
Notice there two global validators in the last. They should be performed only if email is not empty and has valid format, and password is not empty, so I put the in global.
I want to display Email doesn't exist beside email input, and Password incorrect beside password input, how to do that in view?
At present, I use loginForm.globalError, but it will show both of them beside one input.
@inputText(loginForm("email"), '_label->"Email:",
'_error->loginForm.globalError
)
@inputPassword(loginForm("password"), '_label->"Password:")
IMHO, the global error should stay global, so I’d put it above your inputs:
Otherwise you’d have to do something like this: