7

I am working with Play 2.0.4 and have the following form in my scala template.

@fieldGroup(field: Field, className: String = "field") = {
<div class="twipsies well @className">

    <a class="removeField btn danger pull-right">Remove Field</a>

    @inputText( // <=== I need a hidden input field here
        field("id")
    )

    @inputText(
        field("name"),
        '_label -> "Name",
        '_help -> "Use lower case, starts with an alphabet can contain numbers and underscores."
    )
}

I need a few hidden fields in my forms, how do I bind it to the server side Form component? I have seen a @inputHidden template helper in the github repository but it is not available in the stable release. How do I accomplish what I am looking for? Thanks.

Adriano
  • 19,463
  • 19
  • 103
  • 140
Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
  • Had a similar issue, just posted a solution here: http://stackoverflow.com/questions/16911393/how-to-hide-a-text-field-in-play-framework/26096702#26096702] – FrancescoM Sep 29 '14 at 09:37
  • "Handling HTML input creation yourself" http://stackoverflow.com/questions/24728377/play-scala-form-helper-with-custom-html – Adriano Dec 17 '14 at 09:39

2 Answers2

19

Write it 'manually' as common HTML:

<input type="hidden" name="id" value='@field("id").value' >

or use a way described in the documentation in Handling HTML input creation yourself section.

biesior
  • 55,576
  • 10
  • 125
  • 182
3

Use raw HTML:

<input type="hidden" name="@field("id").name" value='@field("id").value' >
Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56