Sha256: ad9c93a178dd96e3da296a4c06dd17ba1cf563169d5a2740bf5ff63faa908019

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

# rubocop:disable Metrics/ParameterLists
require "decidim/form_builder"

module Decidim
  # This custom FormBuilder is used to create resource filter forms
  class FilterFormBuilder < FormBuilder
    # Wrap the radio buttons collection in a custom fieldset.
    # It also renders the inputs inside its labels.
    def collection_radio_buttons(method, collection, value_method, label_method, options = {}, html_options = {})
      fieldset_wrapper options[:legend_title] do
        super(method, collection, value_method, label_method, options, html_options) do |builder|
          if block_given?
            yield builder
          else
            builder.label { builder.radio_button + builder.text }
          end
        end
      end
    end

    # Wrap the check_boxes collection in a custom fieldset.
    # It also renders the inputs inside its labels.
    def collection_check_boxes(method, collection, value_method, label_method, options = {}, html_options = {})
      fieldset_wrapper options[:legend_title] do
        super(method, collection, value_method, label_method, options, html_options) do |builder|
          if block_given?
            yield builder
          else
            builder.label { builder.check_box + builder.text }
          end
        end
      end
    end

    # Wrap the category select in a custom fieldset.
    def categories_select(method, collection, options = {})
      fieldset_wrapper options[:legend_title] do
        super(method, collection, options)
      end
    end

    private

    # Private: Renders a custom fieldset and execute the given block.
    def fieldset_wrapper(legend_title)
      @template.content_tag(:div, "", class: "filters__section") do
        @template.content_tag(:fieldset) do
          @template.content_tag(:legend) do
            @template.content_tag(:h6, legend_title, class: "heading6")
          end + yield
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-core-0.4.4 lib/decidim/filter_form_builder.rb
decidim-core-0.4.2 lib/decidim/filter_form_builder.rb
decidim-core-0.4.1 lib/decidim/filter_form_builder.rb
decidim-core-0.4.3 lib/decidim/filter_form_builder.rb
decidim-core-0.4.0 lib/decidim/filter_form_builder.rb
decidim-core-0.3.2 lib/decidim/filter_form_builder.rb
decidim-core-0.3.1 lib/decidim/filter_form_builder.rb
decidim-core-0.3.0 lib/decidim/filter_form_builder.rb
decidim-core-0.2.0 lib/decidim/filter_form_builder.rb