1

我正在尝试使用 twitter 引导框架在游戏框架中构建一个表单。

我想在多行中排列控件。而且我还想拥有引导程序提供的验证消息。有没有办法做到这一点?

<form class="form">

    @****
    * This works
    *****@

    <div class="controls controls-row">
        <input type="text" id="inputWarning" placeholder="placeholder">
        <input type="text" id="inputWarning" placeholder="placeholder">
    </div>

    @****
    * Why doesn't this work?
    *****@
    <div class="controls controls-row">
        <div class="control-group warning">
            <label class="control-label" for="inputWarning">Input with warning</label>
            <div class="controls">
                <input type="text" id="inputWarning">
                <span class="help-inline">Something may have gone wrong</span>
            </div>
        </div>
        <div class="control-group warning">
            <label class="control-label" for="inputWarning">Input with warning</label>
            <div class="controls">
                <input type="text" id="inputWarning">
                <span class="help-inline">Something may have gone wrong</span>
            </div>
        </div>
    </div>

</form>
4

1 回答 1

2

您可以使用Twitter 引导文档form-horizontal中描述的类来构建水平表单。

Play 提供了表单模板助手,可以更轻松地呈现表单。不幸的是,Play 附带的 Twitter Bootstrap 模板助手不适用于横向表单,并且将在下一个 play 版本中被弃用

我认为最好的解决方案是编写自己的 Bootstrap 模板助手,例如 f.ex。app/views/twitterBootstrapInput.scala.html

@(elements: helper.FieldElements)  

<div class="control-group @if(elements.hasErrors) {error}">
  @if(elements.label.toString.nonEmpty) { <label class="control-label" for="@elements.id">@elements.label</label> }
  <div class="controls">
  @elements.input

    <p class="help-inline">@elements.infos.mkString(", ")</p>  
}  
    @if(elements.hasErrors) { <p class="help-block">@elements.errors.mkString(", ")</p> }  
  </div>
</div>

然后,您可以像这样构建一个水平表单:

@(args...)

@import helper._
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) } 

@helper.form(routes.myRoute(args), 'class -> "form-horizontal") {
   @select(
     editOptions("highlightStyle"),
     Seq("abc" -> "def", "ghi" -> "jkl"),
     '_label -> "Source style:"
   )
}
于 2013-03-23T06:46:50.230 回答