Class: Avo::Fields::BooleanGroupField::EditComponent
- Inherits:
-
EditComponent
- Object
- ViewComponent::Base
- BaseComponent
- EditComponent
- Avo::Fields::BooleanGroupField::EditComponent
- Defined in:
- app/components/avo/fields/boolean_group_field/edit_component.rb
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Attribute Summary
Attributes inherited from EditComponent
#compact, #field, #form, #index, #kwargs, #multiple, #resource, #stacked, #view
Instance Method Summary collapse
-
#checked?(id) ⇒ Boolean
Get the state of each checkboxe from either the form that returns a validation error or from the model itself.
-
#initialize ⇒ EditComponent
constructor
A new instance of EditComponent.
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, #resource_grid, #resource_show_path, #resource_table
Methods inherited from BaseComponent
Methods included from Concerns::FindAssociationField
Constructor Details
#initialize ⇒ EditComponent
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(...) # Initialize 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.
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.with_indifferent_access[id] end end |