SimpleForm default input class

◇◆丶佛笑我妖孽 提交于 2019-12-01 19:38:30

I had a similar issue and after some research I found out that this is not supported using the wrapper 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

You can achieve this like this: simple_form_for(@my_instance, defaults: { input_html: { class: 'span12' }})

You can also choose to use a custom formbuilder. https://github.com/plataformatec/simple_form#custom-form-builder

You can simply override the simple_form default for string input by adding a string_input.rb class file to your rails load path (i.e. app/inputs/string_input.rb) and include as follow:

class StringInput < SimpleForm::Inputs::StringInput
  def input_html_classes
    super.push('span12')
  end
end

If you need to add more default classes to other types of input, you can check out the various input types provided:

https://github.com/plataformatec/simple_form/tree/master/lib/simple_form/inputs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!