simple_form_for rails radio button inline

后端 未结 6 1339
半阙折子戏
半阙折子戏 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-31 00:01

    A simple solution:

    Add a class to the item wrapper. This class can be whatever you choose. I'm using 'inline' in the example below:

    form.input :my_field, as: 'radio_buttons' wrapper_html: {class: 'inline'}
    

    Then define some CSS which only applies to radio button groups (and only the actual radio buttons, not the item label):

    input.radio_buttons.inline label.radio{
      display: inline-block;
    }
    

    Here's an example of what this yields:

    The above yields this result

提交回复
热议问题