simple_form_for rails radio button inline

后端 未结 6 1328
半阙折子戏
半阙折子戏 2021-01-30 23:26

I am trying to get my buttons to display inline and also have a default value because it can\'t be blank. I am usingplataformatex/simple_form and bootstrap.

= f.         


        
6条回答
  •  鱼传尺愫
    2021-01-30 23:56

    If you want them inline, you need to give the labels the inline class by doing: :item_wrapper_class => 'inline'

    Here is an example using your code:

    = f.input :is_private, 
              :collection => [[true, 'Private'], [false, 'Public']], 
              :label_method => :last, 
              :value_method => :first,
              :as => :radio_buttons, 
              :item_wrapper_class => 'inline',
              :checked => true
    

    EDIT: I just realized that my answer was more specific to simple_form + bootstrap, since bootstrap already has styles defined when giving the label's the inline class. You should be able to use my example though, it will just take some more work on your end in creating your custom css.

提交回复
热议问题