codingsplash
codingsplash

Reputation: 5045

Avoiding template helpers in play2.0

I have a form which has a input text field bound to an attribute:

 @helper.inputText(myForm("username"))

But I wish to avoid helpers for the input field. I want to bind the input text field directly with the attribute in the model, something like:

<input type="text" value=@myForm("username")>

Any pointers on how to do this?

Upvotes: 2

Views: 1329

Answers (3)

biesior
biesior

Reputation: 55798

You forgot name attribute

<input type="text" name="username" value='@myForm("username").value' id="youCanAddyourId" class="orClass">

Upvotes: 0

Leonard Punt
Leonard Punt

Reputation: 1051

@myForm("username") returns a Field object. So you can access its variables. In your case you want to fill the value of a input field. So you call its value variable: <input type="text" value=@myForm("username").value>. You can access its error(s), contraint(s), format(s) e.g. in the same way.

Upvotes: 6

i.am.michiel
i.am.michiel

Reputation: 10404

As described on the official documentation :

@helper.input(myForm("username")) { (id, name, value, args) =>
    <input type="date" name="@name" id="@id" @toHtmlArgs(args)>
} 

Upvotes: 0

Related Questions