简体   繁体   English

如何使用辅助对象在Play Framework 2.1中的textarea中设置标准值?

[英]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. 我想要实现的是使用Play form-helpers的简单表单,其中包含textarea输入字段。 This textarea however should contain a predefined value. 但是,此textarea应包含预定义的值。

Using plain html this can be done this way: 使用普通的HTML可以这样做:

<textarea>Predefined text</textarea>

What I want to do is the same using the @textarea-helper from Play. 我想要做的是使用Play中的@ textarea-helper。 There is however no Symbol for the content within the textarea (or I simply was not able to find it). 然而,textarea中的内容没有符号(或者我根本无法找到它)。

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

There is no symbol for value like eg 'value or '_value. 没有值的符号,例如'value或'_value。

Here I found the code related to textarea: 在这里,我找到了与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. 这个@value代表textarea的内容。 Where does it come from and how can I set it? 它来自哪里,如何设置它?

From Play's forms documentation : 来自Play的表格文档

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. 我没有尝试过,但我认为这也适用于文本区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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