【发布时间】:2016-07-06 00:17:34
【问题描述】:
我正在使用 SimpleForm + Bootstrap。我需要在复选框输入后立即添加<i></i>tag,如下:
<div class="form-group">
<div class="checkbox">
<label class="checkbox">
<input type="checkbox" >
<i></i>
Label Text
</label>
</div>
</div>
所以我修改了初始化器
#initializers/simple_form_bootstrap.rb
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.wrapper tag: 'div', class: 'checkbox' do |ba|
ba.wrapper tag: 'label' do |bb|
bb.use :input
bb.wrapper tag: 'i' do |baa|
end
bb.use :label_text
end
end
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
但这是插入一个额外的标签标签
<div class="form-group">
<div class="checkbox">
<label>
<label class="checkbox">
<input type="checkbox" >
<i></i>
Label Text
</label>
</label>
</div>
</div>
label.checkbox 是 simple_form 应用的默认标签。即,通过config.boolean_label_class = 'checkbox'。所以看起来我可以删除我的自定义标签包装器。
b.wrapper tag: 'div', class: 'checkbox' do |ba|
# ba.wrapper tag: 'label' do |bb|
bb.use :input
bb.wrapper tag: 'i' do |baa|
end
bb.use :label_text
# end
end
但是标签只围绕输入。
<div class="form-group">
<div class="checkbox">
<label class="checkbox">
<input type="checkbox" >
</label>
<i></i>
Label Text
</div>
</div>
我已尝试启用和禁用 inline_label。我正在使用一个包含默认 simple_form 包装器的新配置文件。唯一的修改如上。
当 use label_input 未被调用时,为什么 Simple_Form 对输入应用标签?
如何配置 simple_form 以包装输入、<i> 标记和带有标签的标签文本?
【问题讨论】: