I have a problem with form , the problem is that I can’t show error in view properly(I think so). Validation works fine.
When the old password is incorrect error message is displayed below input box on the other hand when passwords are mismatched error isn’t appearing anywhere.
If I do some debug I get data:
from in view:
@pass_form("password").errors
I get this:
FormError(password,Passwords dont match,WrappedArray())
So my question how to fix form or code in view, to print that error properly.
Form(
mapping(
"old_password" -> text.verifying(Messages("forms.password.old.mismatch"),
password => User.correct_?(user.id, password)),
"password" -> tuple(
"new" -> text(minLength = conf.getInt("password.length.min").get),
"confirm" -> text).verifying(Messages("forms.password.new.mismatch"),
passwords => passwords._1 == passwords._2)
)
((_, password) => password._1)((_) => Some(("", ("", ""))))
)
In view I have:
@helper.form(action = routes.UserController.submitPassword) {
@helper.input(pass_form("old_password")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
@helper.input(pass_form("password.new")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
@helper.input(pass_form("password.confirm")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
<input type="submit" value="Set">
}
first of all you might want to use the helper method for your password fields, since there is one for them. Have a look at
views.html.helper.inputPasswordand use it like so:The reason why the Passwords don’t match error is not displayed is, that it is an error bound to the form itself and not to a specific field. You will have to check the
errorsfield of your form for that, which will give you aSeq[FormError]. You can then display these in an appropriate manner…Best regards