Class: Avo::Fields::CheckboxListField::EditComponent

Inherits:
EditComponent show all
Defined in:
app/components/avo/fields/checkbox_list_field/edit_component.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Attribute Summary

Attributes inherited from EditComponent

#field, #form, #full_width, #index, #kwargs, #multiple, #resource, #stacked, #view

Instance Method Summary collapse

Methods inherited from EditComponent

#classes, #disabled?, #field_wrapper_args, #render?

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods inherited from BaseComponent

#component_name, #hotkey_badge

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #manual_frame_cookie_name, #manual_frame_remembered?, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_header_menu_items, #render_license_warning, #root_path_without_url, #rtl?, #safe_blob_path, #safe_blob_representation_url, #safe_blob_url, #text_direction, #ui, #wrap_in_modal

Methods included from SummaryChartHelper

#summary_chart_params_for

Methods included from Concerns::FindAssociationField

#find_association_field

Constructor Details

#initializeEditComponent

Returns a new instance of EditComponent.



4
5
6
7
8
9
10
11
12
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 4

def initialize(...)
  super

  @data = @field.get_html(:data, view: view, element: :input)
  @style = @field.get_html(:style, view: view, element: :input)
  @form_scope = @form.object_name
  @options = @field.options
  @inline_search = @field.inline_search?
end

Instance Method Details

#checkbox_list_field_dataObject



46
47
48
49
50
51
52
53
54
55
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 46

def checkbox_list_field_data
  return {} unless inline_search?

  {
    controller: "checkbox-list-field",
    action: "input->checkbox-list-field#filter keydown->checkbox-list-field#handleKeydown",
    checkbox_list_field_hidden_selections_one_value: t("avo.checkbox_list.hidden_selections.one"),
    checkbox_list_field_hidden_selections_other_value: t("avo.checkbox_list.hidden_selections.other")
  }
end

#checkbox_list_idObject



38
39
40
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 38

def checkbox_list_id
  @checkbox_list_id ||= field_dom_id(:checkbox_list)
end

#checked?(id) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 14

def checked?(id)
  stored_ids.include? @field.normalize_id(id)
end

#inline_search?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 26

def inline_search?
  @inline_search && selectable_options.any?
end

#inline_search_aria_labelObject



61
62
63
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 61

def inline_search_aria_label
  "#{inline_search_label} #{@field.name}"
end

#inline_search_input_idObject



42
43
44
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 42

def inline_search_input_id
  @inline_search_input_id ||= field_dom_id(:inline_search)
end

#inline_search_labelObject



57
58
59
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 57

def inline_search_label
  t("avo.search.placeholder")
end

#input_html_id(id) ⇒ Object



22
23
24
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 22

def input_html_id(id)
  field_dom_id(id)
end

#input_nameObject



18
19
20
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 18

def input_name
  @input_name ||= "#{@form_scope}[#{@field.id}][]"
end

#more_records_hintObject



34
35
36
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 34

def more_records_hint
  @options.find { |option| @field.option_hint?(option) }
end

#selectable_optionsObject



30
31
32
# File 'app/components/avo/fields/checkbox_list_field/edit_component.rb', line 30

def selectable_options
  @selectable_options ||= @options.select { |option| !@field.option_hint?(option) }
end