有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在play框架的form helper中隐藏标签?

我有一个表单,用户可以在其中输入问题。每个字段都有一个标签,但在生产环境中,我不想显示标签和某些inputText字段。我试图通过使用'style -> "display: none"删除inputText字段而不是标签来摆脱它们。我没有在play framework网站上找到对此的解释:https://www.playframework.com/documentation/2.0.4/JavaFormHelpers

有没有一种方法可以通过内置工具实现这一点,或者还有其他的可能性

@import helper._
@import helper.twitterBootstrap._

@helper.form(action = routes.Application.sendQuestion()){
        <fieldset>
            @helper.inputText(questionForm("questionID"),'style -> "display: none")
            @helper.inputText(questionForm("questionText"))
            @helper.inputText(questionForm("voteScore"))
            @helper.inputText(questionForm("ownerID"))
            @helper.inputText(questionForm("page"))
        </fieldset>
        <input type="submit" class="btn btn-default">
    }

共 (1) 个答案

  1. # 1 楼答案

    您可以以编写自己的字段构造函数的形式隐藏标签,例如:

    编写自己的字段构造函数

    @(elements: helper.FieldElements)
    
    <div class="@if(elements.hasErrors) {error}">
        <div class="input">
            @elements.input
            <span class="errors">@elements.errors.mkString(", ")</span>
            <span class="help">@elements.infos.mkString(", ")</span> 
        </div>
    </div>
    

    有关详细信息-https://www.playframework.com/documentation/2.0/JavaFormHelpers