微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails-3 – 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

解决方法

我有一个类似的问题,经过一些研究后我发现使用包装器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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐