Scala Play framework: Binding form parameters to hidden fields

烂漫一生 提交于 2019-12-21 12:02:24

问题


I am working with Play 2.0.4 and have the following form in my scala template.

@fieldGroup(field: Field, className: String = "field") = {
<div class="twipsies well @className">

    <a class="removeField btn danger pull-right">Remove Field</a>

    @inputText( // <=== I need a hidden input field here
        field("id")
    )

    @inputText(
        field("name"),
        '_label -> "Name",
        '_help -> "Use lower case, starts with an alphabet can contain numbers and underscores."
    )
}

I need a few hidden fields in my forms, how do I bind it to the server side Form component? I have seen a @inputHidden template helper in the github repository but it is not available in the stable release. How do I accomplish what I am looking for? Thanks.


回答1:


Write it 'manually' as common HTML:

<input type="hidden" name="id" value='@field("id").value' >

or use a way described in the documentation in Handling HTML input creation yourself section.




回答2:


Use raw HTML:

<input type="hidden" name="@field("id").name" value='@field("id").value' >


来源:https://stackoverflow.com/questions/12913840/scala-play-framework-binding-form-parameters-to-hidden-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!