I have the below model, view and error messages.
Model
public class LoginModel {
@Required(message = "validation.required.email")
public String email;
@Required(message = "validation.required.password")
public String password;
}
View
@for((field, validationErrors) <- myForm.errors) {
@for(validationError <- validationErrors) {
<li>@Messages(validationError.message)</li>
}
}
conf/messages
error.no_email=You must enter an email
error.no_password=You must enter a password
The message "You must enter a password" appears before the "You must enter an email". I would like them in the same order I have them on my form (which is email followed by password). Is there a way to define the order which error messages are displayed when errors are added automatically by play from validation annotations?
It's a bit of an overheard (and I don't like the solution) but it's possible via:
It still means that the order of the messages are not guaranteed for each field, but at least you can enforce the order at a field level so they can match up to the order of the fields on your form.