Class: Avo::Fields::BooleanGroupField::EditComponent

Inherits:
EditComponent
  • Object
show all
Defined in:
app/components/avo/fields/boolean_group_field/edit_component.rb

Instance Attribute Summary

Attributes inherited from EditComponent

#compact, #field, #form, #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_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table

Constructor Details

#initializeEditComponent

Returns a new instance of EditComponent.



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

def initialize(...)
  super(...)

  # Initilize here to avoid multiple calls to @field.get_html for each option.
  @classes = "w-4 h-4 rounded checked:bg-primary-400 focus:checked:!bg-primary-400" \
    "#{@field.get_html(:classes, view: view, element: :input)}"
  @data = @field.get_html(:data, view: view, element: :input)
  @style = @field.get_html(:style, view: view, element: :input)
  @form_scope = @form.object_name
end

Instance Method Details

#checked?(id) ⇒ Boolean

Get the state of each checkboxe from either the form that returns a validation error or from the model itself.

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'app/components/avo/fields/boolean_group_field/edit_component.rb', line 16

def checked?(id)
  if params[@form_scope].present? && params[@form_scope][@field.id.to_s].present?
    params[@form_scope][@field.id.to_s].include?(id.to_s)
  elsif @field.value.present?
    @field.value[id.to_s]
  end
end