【问题标题】:twitter bootstrap form arrange fields horizontally - play frameworktwitter bootstrap 表单水平排列字段 - 播放框架
【发布时间】:2013-03-23 14:46:50
【问题描述】:

我正在尝试使用 twitter bootstrap 框架构建一个表单播放框架。

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

<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>

【问题讨论】:

    标签: twitter-bootstrap playframework playframework-2.0


    【解决方案1】:

    您可以使用Twitter bootstrap documents 中描述的form-horizontal 类来构建水平表单。

    Play 提供了Form template helpers,使渲染表单变得更加容易。不幸的是,Play 附带的 Twitter Bootstrap 模板助手不适用于水平表单,并且会得到 deprecated in the next play version

    我认为最好的解决方案是编写自己的 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:"
       )
    }
    

    【讨论】:

    • 谢谢,但我的问题有点不同。使用 twitterBootstrapInput 字段构造函数,我可以在一行中有一个标签和一个输入。但是,我想做的是在一行中有多个输入框。如果我使用 @inputText 帮助器,它会在单独的行上创建每个输入框。
    猜你喜欢
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2012-08-25
    相关资源
    最近更新 更多