SimpleForm 默认输入类

2023-11-21

我正在使用 SimpleForm + Bootstrap。如何为所有属性添加属性type="text"输入类 =span12?

输出类似这样的东西:

<div class="controls"><input autofocus="autofocus" class="string required span12" id="user_first_name" name="user[first_name]" required="required" size="50" type="text" value=""></div>

我尝试玩config.wrappers但是这个

ba.use :input,  :wrap_with => { :class => 'span12' }

不起作用。它添加到包装器而不是修改输入标签。有什么想法吗?

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
  config.default_wrapper = :bootstrap
end

您可以通过将 string_input.rb 类文件添加到 Rails 加载路径(即 app/inputs/string_input.rb)来简单地覆盖字符串输入的 simple_form 默认值,并包含如下内容:

class StringInput < SimpleForm::Inputs::StringInput
  def input_html_classes
    super.push('span12')
  end
end

如果需要为其他类型的输入添加更多默认类,可以查看提供的各种输入类型:

https://github.com/plataformatec/simple_form/tree/master/lib/simple_form/inputs

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SimpleForm 默认输入类 的相关文章

随机推荐