Class: Decidim::FilterFormBuilder

Inherits:
FormBuilder
  • Object
show all
Defined in:
decidim-core/lib/decidim/filter_form_builder.rb

Overview

This custom FormBuilder is used to create resource filter forms

Instance Method Summary collapse

Methods inherited from FormBuilder

#areas_select, #attachment, #categories_select, #check_box, #choose_button_label, #collection_check_boxes, #collection_radio_buttons, #create_language_selector, #data_picker, #editor, #form_field_for, #hashtaggable_text_field, #label_for, #max_file_size, #password_field, #resources_select, #scopes_picker, #social_field, #text_area, #translated, #translated_one_locale, #upload, #upload_help

Methods included from Map::Autocomplete::FormBuilder

#geocoding_field

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#collection_filter(method:, collection:, label_scope:, id:, **options) ⇒ ActionView::OutputBuffer

This method is used to generate a section of options in a filter block.

Parameters:

  • method (Symbol)

    The method associated to the filter object of the form builder.

  • collection (Array, Decidim::CheckBoxesTreeHelper::TreeNode)

    The collection used to display the options. It can be an array of options where each options if represented by an array containing a value and a name or a check_boxes_tree struct as defined in Decidim::CheckBoxesTreeHelper for more complex situations which require nested options.

  • label_scope (String)

    The scope used to translate the title of the section.

  • id (String)

    The id of the section. It is also used to get the translation of the section title.

  • options (Hash)

    Additional options. Except :type, the rest of options are passed to the partial used to generate the section.

Options Hash (**options):

  • :type (Symbol, String)

    The type of selector to use with the collection. It can be check_boxes, radio_buttons or check_boxes_tree (used by default when tree struct is passed. The default selector for arrays is radio_buttons.

Returns:

  • (ActionView::OutputBuffer)

    the HTML of the generated collection filter.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'decidim-core/lib/decidim/filter_form_builder.rb', line 26

def collection_filter(method:, collection:, label_scope:, id:, **options)
  type = options.delete(:type) || default_form_type_for_collection(collection)

  case type.to_s
  when "check_boxes", "check_box", "radio_buttons", "radio_button"
    options.merge!(builder_type: type.to_s.pluralize)
    type = "collection"
  when "check_boxes_tree"
    options.merge!(check_boxes_tree_id: check_boxes_tree_id(method))
  end

  @template.render(
    "decidim/shared/filters/#{type}",
    **options.merge(
      method:,
      collection:,
      label_scope:,
      id:,
      form: self
    )
  )
end


49
50
51
# File 'decidim-core/lib/decidim/filter_form_builder.rb', line 49

def dropdown_label(item, method, options = {})
  @template.render("decidim/shared/filters/dropdown_label", **options.merge(item:, method:, form: self))
end