简体   繁体   中英

How can I set a standard value in a textarea in Play Framework 2.1 using the helper object?

What I am trying to achieve is a simple form using the Play form-helpers which contains a textarea input-field. This textarea however should contain a predefined value.

Using plain html this can be done this way:

<textarea>Predefined text</textarea>

What I want to do is the same using the @textarea-helper from Play. There is however no Symbol for the content within the textarea (or I simply was not able to find it).

@textarea(myForm("text"), 'rows -> 30, '_label -> "MyLabel")

There is no symbol for value like eg 'value or '_value.

Here I found the code related to textarea:

@**
 * Generate an HTML textarea.
 *
 * Example:
 * {{{
 * @textarea(field = myForm("address"), args = 'rows -> 3, 'cols -> 50)
 * }}}
 *
 * @param field The form field.
 * @param args Set of extra attributes.
 * @param handler The field constructor.
 *@
@(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang)

@input(field, args:_*) { (id, name, value, htmlArgs) =>
    <textarea id="@id" name="@name" @toHtmlArgs(htmlArgs)>@value</textarea>
}

There is this @value which represents the content of the textarea. Where does it come from and how can I set it?

From Play's forms documentation :

Fill a form with initial default values Sometimes you'll want to populate a form with existing values, typically for editing data:

val filledForm = userForm.fill(User("Bob", 18))

I haven't tried it, but I would assume that this should work for text areas as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM