First of all I want to state that I think that the Play documentation for 2.0 is really, really bad.
I\'m looking for a way to place a validation error underneath a HTML
I use this code to display a global bootstrap alert box with on the form:
@if(form.hasErrors) {
x
@if(form.errors.size() > 0) {
@for((key, value) <- form.errors) {
@key.toString() :
@for(err <- value) {
@err.message().toString()
}
}
} else {No error returned.}
}
The output for an form error key-value pair is a bootstrap alert box with @key.toString() : @value.message.toString
.
If you wanted to display the error at the field level instead, you would want to modify it slightly with another conditional statement for the form.errors map value so that it only triggered for the specific field. I haven't tested this, but it'd go something like:
@if(form.hasErrors) {
@if(form.errors.size() > 0) {
@for((key, value) <- form.errors) {
@for(err <- value) {
@if(err.contains("YourSelectFieldName")) {
@err.message().toString()
}
}
}
}
}