I still struggle with the form validation and form helpers in Play 2.0. I have this login screen that I use together with the Twitter Bootstrap. So my login form looks like this
I'm in the same battle to show the errors :) for now I'm using :
<span class="errors badge badge-important">@elements.errors.mkString(", ")</span>
That would be hidden if there is no error, take a look on this : http://twitter.github.com/bootstrap/components.html#labels-badges
but still looking for a way to translate "Required" to portuguese.
The info text comes from @elements.infos.mkString(", ")
. To show the errors, you should use @elements.errors(elements.lang).mkString(", ")
instead.
The correct parameter to change the infos content would be help (this is a bit inconsistent, you have to read the source to realize this) so if you want to use the built-in bootstrap fields but suppress the infos, you'd pass '_help -> ""
.
Edit for #4:
Here's how you should call your specific checkbox:
@checkbox(loginForm("remember"), '_label -> Messages("login.remeberme"))(handler = implicitFieldConstructor, implicitly[Lang])
And yes, @input
means there's a template called input.scala.html
. It's the basic template for all input helpers.
To understand why and how this works, you should dive a little deeper into Play 2.0 and Scala (esp. implicit arguments).
<span class="help-inline">@elements.infos.mkString(", ")</span>
. You are displaying the information about the field there. Remove it to don't display the information.Add this code:
@if(elements.hasErrors) {
<span class="help-inline">@elements.infos.mkString(", ")</span>
}
To set the classname: add this to your Twitter Bootstrap field: class="@elements.args.get('_class)
. And in your login form add the class parameter, like this: @inputText(loginForm("email"), '_label -> "Email", '_class -> "classname")
To understand the concept, take a look at the source code: https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/views/helper/defaultFieldConstructor.scala.html