加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – SimpleForm默认输入类

发布时间:2020-12-17 03:39:34 所属栏目:百科 来源:网络整理
导读:我正在使用SimpleForm Bootstrap.如何使用class = span12为所有type =“text”输入添加属性? 输出如下内容的东西: div class="controls"input autofocus="autofocus" class="string required span12" id="user_first_name" name="user[first_name]" requir
我正在使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读