Reputation: 109
If I use the form
helper to get a loginForm
at my site, how can I customize the input label? Of course, the label which is set is the name of the variable in my Java class. However, I want another label name than the variable name.
At this point the only way to change it, I found, is to set up a completely new form builder. In this, I look if the element I want to illustrate is the element I want to set a new label and then set the other label. However, I think this is very much overdone.
Is there an easy variable I can add at the end of the @helper.input
statement to change the label name?
I am using PlayFramework 2.6.
Upvotes: 2
Views: 947
Reputation: 12214
Yes. You just need to add a '_label
parameter in our input. For example:
@(userForm: Form[User])
@helper.form(action = routes.UsersController.save()) {
@helper.inputText(userForm("name"), '_label -> "Your name")
@helper.inputText(userForm("email"), '_label -> "Your E-mail")
}
Pay attention that it has a '
only at the start. This is documented here:
https://playframework.com/documentation/2.6.x/JavaFormHelpers
Another way to do that, if you need to highly customized the generate HTML is by handling HTML input creation yourself.
Upvotes: 5