how to add a class to the input component in a wrapper in simple_form 2

前端 未结 5 1063
难免孤独
难免孤独 2021-02-04 04:57

I am trying to have class=\"text\" in my input fields when using a custom wrapper called :hinted in simple_form 2.0.0.rc

config.wrappers :hinted do          


        
5条回答
  •  清歌不尽
    2021-02-04 05:59

    This feature is about to be merged to master right now (Oct. 2012):

    https://github.com/plataformatec/simple_form/pull/622

    Then you can do something like this to add HTML attributes directly on the input field:

    SimpleForm.build :tag => :div, :class => "custom_wrapper" do |b|
      b.wrapper :tag => :div, :class => 'elem' do |component|
        component.use :input, :class => ['input_class_yo', 'other_class_yo']
        component.use :label, :"data-yo" => 'yo'
        component.use :label_input, :class => 'both_yo'
        component.use :custom_component, :class => 'custom_yo'
      end
    end
    

提交回复
热议问题