Sha256: a19c7015e352aebb54f2a69428e881fc1bba5bbed0e46233fd03cc54b8cb74ac

Contents?: true

Size: 1.92 KB

Versions: 7

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

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.1.0 lib/decidim/filter_form_builder.rb
decidim-core-0.0.8.1 lib/decidim/filter_form_builder.rb
decidim-core-0.0.7 lib/decidim/filter_form_builder.rb
decidim-core-0.0.6 lib/decidim/filter_form_builder.rb
decidim-core-0.0.5 lib/decidim/filter_form_builder.rb
decidim-core-0.0.3 lib/decidim/filter_form_builder.rb
decidim-core-0.0.2 lib/decidim/filter_form_builder.rb