我正在使用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
解决方法
我有一个类似的问题,经过一些研究后我发现使用包装器api不支持.
The best you can do is use the :defaults option in each form,instead of adding for every input.
https://github.com/plataformatec/simple_form/issues/754
您可以这样实现:simple_form_for(@my_instance,默认值:{input_html:{class:’span12′}})
您也可以选择使用自定义formbuilder.
https://github.com/plataformatec/simple_form#custom-form-builder