simple_form collection wrapper (radios buttons) : double encapsulation of items

后端 未结 3 979
醉话见心
醉话见心 2021-02-15 12:57

I\'d like to reproduce this html sequence of radio buttons with simple_form in order to make simple_form work with http://semantic-ui.com/ syntax :

  
3条回答
  •  无人及你
    2021-02-15 13:36

    With updated versions 'simple_form', '~> 3.0.2' and Semantic UI 0.19.3, I achieved it with following code.

    class SemanticCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
      def input
        label_method, value_method = detect_collection_methods
        options[:collection_wrapper_tag] = 'div'
        options[:collection_wrapper_class] = 'grouped inline fields'
    
        @builder.send("collection_check_boxes",
                      attribute_name, collection, value_method, label_method,
                      input_options, input_html_options, &collection_block_for_nested_boolean_style
        )
      end
    
      protected
      def item_wrapper_class
        "ui checkbox field"
      end
    end
    

    and in the view

    = f.association :branches, as: :semantic_check_boxes
    

    Here is the output:

    enter image description here

提交回复
热议问题