How to hide a text field in play framework? For example how to hide this field:
@inputText(userProfileForm("name"), '_label -> "Name")
How to hide a text field in play framework? For example how to hide this field:
@inputText(userProfileForm("name"), '_label -> "Name")
The
inputText
helper takes a varargs of(Symbol, Any)
, which represent the html attributes. If you are using html5 you can just add the hidden attribute:normally the
hidden
attribute has no value, but I couldn't find any information about how to do this with the helpers. In Chrome at least it works like this as well.edit:
btw, you can also just use html instead of the helper:
This should work in all browsers:
Note that this only hides the field, not the label etc.
If you want to hide the label aswell, you can't do this with the default helpers. You can however specify the input field yourself:
The
name
should be name of the field in your form (coincidentallyname
aswell in this case).I haven't tested the
value
but it should work, maybe you'll need to strip the"
aroundname
.If you do this, the hidden data will be sent, along with the other data in the form to the server.
Edit:
If the hidden value is empty, that means you didn't bind it to the form when calling the view. You can bind the name to the form like this in Java (I don't know Scala, but it's explained in the Play Scala documentation):
Another option (which is cleaner in my opinion) is to simply pass the username as an argument to the view. The controller becomes:
And in the view you can then simply do:
I know that this is an old question, but i had a similar issue, i wanted to hide an inputText and still, handle it using the helpers. The best and cleanest way to do it is to write your own helper adding a custom value to tell when to hide the element itself. I came to a solution like this
my own field constructor
that i used in the view file like this:
now you are done :)
While it worked, I didn't like the hashmap version provided by @Aerus, preferring to use the statically typed forms when possible, so I came up with an alternative.
Then, in the profile, you can do as follows: