无法将类属性添加到单选按钮输入生成的标签

时间:2017-12-27 03:50:59

标签: html ruby-on-rails twitter-bootstrap ruby-on-rails-4 simple-form

我有以下配置:

# config/initializers/simple_form.rb
config.item_wrapper_tag = :div
config.item_wrapper_class = 'form-check'

# config/initializers/simple_form_bootstrap.rb

config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  b.use :html5
  b.optional :readonly
  b.use :label, class: 'control-label'
  b.use :input, class: 'form-check-input'
  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 radio_buttons required profile_sex">
  <label class="control-label radio_buttons required">
    <abbr title="required">*</abbr> 
    Gender
  </label>
  <div class="radio form-check">
    <label for="profile_sex_male">
      <input class="form-check-input radio_buttons required" value="Male" name="profile[sex]" id="profile_sex_male" type="radio">
      Male          
    </label>
  </div>
  <div class="radio form-check">
    <label for="profile_sex_female">
      <input class="form-check-input radio_buttons required" value="Female" name="profile[sex]" id="profile_sex_female" type="radio">
      Female
    </label>
  </div>
</div>

在Bootstrap v4.0.0-beta.2中,为了改善单选按钮的布局和定位,应该有一个单选按钮具有以下结构:

<div class="form-check">
  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" value="">
    Male
  </label>
</div>

参考Bootstrap#forms

观察附加到标签的class属性 - form-check-label。如何将此html类添加到simple_forms中的单选按钮集合生成的标签?

0 个答案:

没有答案