【问题标题】:Grouping checkboxes for individual boolean values using css, twitter-bootstrap, and simple_form使用 css、twitter-bootstrap 和 simple_form 为单个布尔值分组复选框
【发布时间】:2012-10-23 21:13:02
【问题描述】:

你能帮我格式化这个 simple_form 吗?

我正在使用这个表格:

<%= simple_form_for @my_model, :html => { :class => 'form-horizontal'} do |f| %>
<%= f.error_notification %>
    <div class="form-inputs">
      <%= f.input :some_text, :input_html => {:class => "span6", :rows => 2}%>
      <%= f.input :a_description, :input_html => {:class => "span6", :rows => 2}%>  
      <%= f.input :boolean1%>
      <%= f.input :boolean2%>
      <%= f.input :boolean3%>
      <%= f.input :boolean4%>
      <%= f.input :boolean5%>
      <%= f.input :boolean6%>
      <%= f.input :boolean7%>
      <%= f.input :boolean8%>
      <%= f.input :id, :as => :hidden, :input_html => { :value => @my_model.id }%>
  </div>
  <div class="form-actions">
    <%= f.button :submit, :class => 'btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                special_path, :class => 'btn' %>
  </div>
<% end %>

我想将布尔值显示为两列复选框,每列垂直堆叠有 4 个复选框。

类似

Some text:      [input]
A description:  [input] 
                bool1    bool5
                bool2    bool6
                bool3    bool7
                bool4    bool8

我已经在http://simple-form-bootstrap.plataformatec.com.br/articles/new 克隆了 git 存储库,查看了代码,运行它,我发现它可以工作。
但是......它适用于存储在字符串中的一系列复选框选项。我有一个具有 8 个布尔值的模型,无法理解如何使用 rails、css、twitter-bootstrap 和 simple_form 将它们正确分组。

我已阅读此 SO 帖子:Make all input fields on the same line
...还有这个:Adding controls inline with simple_form, nested_form and Twitter Bootstrap in Rails

...但它们似乎不适合我的特殊情况,我没有想法尝试。

请尝试将您的答案集中在一个特定的代码示例上,该示例显示如何以某种分组方式为单个布尔值布局复选框。

提前致谢!

【问题讨论】:

    标签: css ruby-on-rails twitter-bootstrap formatting simple-form


    【解决方案1】:

    我过去只使用普通的网格控件制作了多列引导表单。在您的情况下,类似于:

    <div class="form-inputs">
      ...
      <div class="row">
        <div class="span6">
          <%= f.input :boolean1 %>
          <%= f.input :boolean2 %>
          ...
        </div>
        <div class="span6">
          <%= f.input :boolean5 %>
          <%= f.input :boolean6 %>
          ...
        </div>
      </div>
      ...
    </div>
    

    然后,您可以使用不同的 spanoffset 类来调整这些列。

    【讨论】:

    • 哇。如此基础。效果很好。谢谢。想想我去了多远,有点尴尬。
    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 2014-10-09
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    相关资源
    最近更新 更多