【问题标题】:Show Label for Simple Form After Hiding by Default默认隐藏后显示简单表单的标签
【发布时间】:2014-08-13 16:21:13
【问题描述】:

我正在使用 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 无法重新添加标签。

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

【问题讨论】:

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


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      相关资源
      最近更新 更多