Play 2 - Template index.scala.html - How do i write an hidden field in Scala?

4,381 views
Skip to first unread message

Laurent Bois

unread,
Apr 5, 2012, 11:33:52 AM4/5/12
to play-fr...@googlegroups.com
Hi

In my project Play 2 ( i'm a beginner on Scala), i have un page view with the following input fields written in Scala.

    @form(routes.Addresses.newAddress()) {

        

        @inputText(addressForm("street")) 

        @inputText(addressForm("postalCode"))

        @inputText(addressForm("city"))

        @inputText(addressForm("country"))

           

        <input type="submit" value="Update">

        

    }


I need to add an hidden field "id" in this Edit Form to have the address primary key.

I don't find how to write this hidden field...any idea?

the html code woould be <input type="hidden" value="33" name="id" />

Thanks for your help


Laurent

Julien Richard-Foy

unread,
Apr 5, 2012, 11:35:47 AM4/5/12
to play-fr...@googlegroups.com
What’s wrong with writing the HTML?

Laurent Bois

unread,
Apr 5, 2012, 11:41:12 AM4/5/12
to play-fr...@googlegroups.com
Nothing wrong except how do i get the addressForm value in scala?

Julien Richard-Foy

unread,
Apr 5, 2012, 12:00:01 PM4/5/12
to play-fr...@googlegroups.com
Oh sorry I misunderstood your question.
You can retrieve the "id" field of your form by writing
“addressForm("id")”. And then you can get the value of this field
using its “value” member:
<input type="hidden" value="@addressForm("id").value" name="id" />

Jacob Groundwater

unread,
Apr 5, 2012, 9:06:44 PM4/5/12
to play-fr...@googlegroups.com
Another reason to write the HTML directly is that the helper methods create labels as well as inputs. If by some means you did use a helper method, your hidden value would spawn non-hidden labels.

That's all they are, helper methods. There is nothing wrong with writing the HTML code directly as Julien stated, and in this case it is the only way.
Message has been deleted

Kevin Bosman

unread,
Apr 6, 2012, 12:02:13 PM4/6/12
to play-fr...@googlegroups.com
That didn't work so well. Try again...


---------- Forwarded message ----------
> That's all they are, helper methods. There is nothing wrong with writing the
> HTML code directly as Julien stated, and in this case it is the only way.

Why not just write your own helper?

Attached is an example.

fieldHidden.scala.html
Reply all
Reply to author
Forward
0 new messages