隐藏默认后显示简单表单的标签

时间:2014-08-13 16:21:13

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

我将rails bootstrapsimple_form一起使用。对于我的大多数输入字段,我只使用占位符文本。我已经注释掉了为字段添加标签的行:

#initializers/simple_form_bootstrap.rb
SimpleForm.setup do |config|
  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    # b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

我知道我可以通过添加label: false手动删除视图中的标签,但label: true无法添加回标签。

如果我的默认设置是不显示标签,如何添加标签?

1 个答案:

答案 0 :(得分:0)

添加另一个包装器,而不是使用您的设置操作默认包装器

config.wrappers :placeholder_form, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end

如果要将此包装用于表单,请使用

simple_form_for @user, wrapper: :placeholder_form

对于默认包装器,不要将包装器属性传递给simple_form_for

相关问题