【发布时间】:2024-05-04 21:45:03
【问题描述】:
我在我当前的 Rails 应用程序中使用 simple form simple_form (v: 3.2.1) 和 bootstrap(其他开发人员以前参与过这个项目)。
从collection 创建单选按钮我使用
= f.input :default_ship,
label: 'foo)',
collection: default_ship_options(@company),
as: :radio_buttons
生成html之类的
<span class="radio radio radio"><label for="foo"><input class="radio_buttons required" required="required" aria-required="true" type="radio" value="company" name="purchasing_source[default_ship]" id="foo"><span></span>Test Shipping Address</label></span>
看这里创建了一个空范围<span></span>,实际上是为了显示复选框。
我的 CSS 代码:
.radio, .checkbox {
position: relative;
display: block;
margin-top: 10px;
margin-bottom: 10px;
}
.radio label, .checkbox label {
min-height: 20px;
padding-left: 20px;
margin-bottom: 0;
font-weight: normal;
cursor: pointer;
}
label input[type=checkbox], label input[type=radio] {
display: none;
}
label input[type=checkbox] + span, label input[type=radio] + span {
display: inline-block;
width: 1.4em;
height: 1.4em;
margin-right: 0.5em;
vertical-align: middle;
cursor: pointer;
border: 1px solid #AAA;
}
现在我的问题是简单的表单不会为checkbox 元素创建额外的span,这就是为什么没有为复选框显示复选框的原因。为复选框生成的 Html 是
<span class="checkbox"><label for="manufacturer_currencies_fr"><input class="check_boxes optional" type="checkbox" value="fr" name="manufacturer[currencies][]" id="manufacturer_currencies_fr">Euro</label></span>
如何为复选框生成额外的span?
(我不想更改我的 CSS,因为它已经使用了很多地方)
在我看来,我必须在simple_form_bootstrap.rb 做点什么,但不确定。也可能是以前的开发人员可能会覆盖某些方法,但我不知道在哪里可以找到。
【问题讨论】:
标签: ruby-on-rails twitter-bootstrap-3 simple-form