SimpleForm默认输入类 [英] SimpleForm default input class
本文介绍了SimpleForm默认输入类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SimpleForm+Bootstrap。如何向具有CLASS=span12
的所有type="text"
输入添加属性?
输出类似以下内容的内容:
<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
推荐答案
您可以通过将一个字符串_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
这篇关于SimpleForm默认输入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文