我正在使用 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
关于ruby-on-rails-3 - SimpleForm 默认输入类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14972253/