Play Framework - how to change the label of a input when using form helpers?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Play Framework - how to change the label of a input when using form helpers?



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.


form


loginForm



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?


@helper.input



I am using PlayFramework 2.6.




1 Answer
1



Yes. You just need to add a '_label parameter in our input. For example:


'_label


@(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.





Thank you very much, this was an very nice answer. I saw this, however thougt that these are only fit in the Formbuilder :)
– Pommeschica
Jan 19 at 11:51






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard