【问题标题】:Generate <input type="search" /> using Play! framework使用 Play 生成 <input type="search" />!框架
【发布时间】:2012-08-27 06:03:25
【问题描述】:

我正在使用 Play 框架。我想使用HTML5 input type 'search'。所以,我想输出:

<input type="search" />

我试过了:

@inputText(field = myForm("myField"), 'type -> "search")

但它仍然保留 type="input"

【问题讨论】:

标签: scala playframework playframework-2.0


【解决方案1】:

方法inputText代表一个HTML输入文本(见源代码here)。

您必须定义自己的模板来定义search 类型的输入。看看Play documentation

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

【讨论】:

    【解决方案2】:

    您的搜索字段很可能不会使用常见表单元素中的许多典型内容(例如 constraintserror 消息),因此您可以使用纯 HTML 插入它,并在适当的属性中添加字段的值(如果完全需要):

    <input type="search" name="myField" value="@myForm("myField").value" />
    

    如果它只是一个搜索表单(只有这个字段),你甚至不需要用 Form 类包装它

    (当然 Nico 的建议在更复杂的场景中是可取的)

    【讨论】:

      【解决方案3】:

      您正在寻找的一些助手可在 play 2 模块中使用。 html5 输入助手不在框架的核心部分,因为游戏作者希望保持轻量。 这是 github 上的模块页面:https://github.com/loicdescotte/Play2-HTML5Tags

      【讨论】:

        猜你喜欢
        • 2012-02-28
        • 1970-01-01
        • 1970-01-01
        • 2016-07-18
        • 2016-05-24
        • 1970-01-01
        • 1970-01-01
        • 2011-05-10
        • 1970-01-01
        相关资源
        最近更新 更多