1

我正在使用 simple_form gem (https://github.com/plataformatec/simple_form) 来帮助我的应用程序中的表单。但我想在 li 标签中显示我在这里得到的许多单选按钮。Simple_form 现在为每个单选按钮生成跨度包装标签。像这样:

 <%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio %>
 #=> <span><input type='radio'><label>1</label></span> 

有什么办法可以让它将输入和标签部分包装在一个 li 而不是 span 中?

谢谢你!

4

2 回答 2

5

您可以像这样传递:item_wrapper_tag给您的输入:

<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio,
                         :item_wrapper_tag => :li %>

您还可以传递:collection_wrapper_tag选项来更改所有无线电输入的包装,如下所示:

<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio,
                         :item_wrapper_tag => :li,
                         :collection_wrapper_tag => :ul %>
于 2011-10-01T23:31:34.517 回答
0

尝试了接受的答案。它很好地将子弹卡在我的单选按钮前面,但它仍然没有显示内联。我只是用 CSS 做的。我在按钮和标签周围拍了一个带有 class="radio-buttons" 的 div。然后我将它添加到我的样式表(SASS)中:

.radio-buttons {
  margin: .5em 0;
  span input {
    float: left;
    margin-right: .25em;
    margin-top: -.25em;
  }
  #this grabs the MAIN label only for my radio buttons 
  #since the data type for the table column is string--yours may be different
  label.string { 
    margin-bottom: .5em !important;
  }

  clear: both;
}

.form-block {
  clear: both;
  margin-top: .5em;
}

 .radio-buttons span {
  clear: both;
  display:block;
 }

这将使所有框架上的单选按钮内联,尽管这已被调整为最适合 Zurb Foundation。;)

于 2013-09-29T06:19:06.153 回答