Sha256: e3c965dae33b0d0d16a2057e295f891ea58f6416ae3da459e4aebd7bf6d93e75

Contents?: true

Size: 934 Bytes

Versions: 18

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::BooleanGroupField::EditComponent < Avo::Fields::EditComponent
  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

  # Get the state of each checkboxe from either the form that returns a validation error or from the model itself.
  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
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
avo-3.16.1 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.16.0 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.7 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.6 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.5 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.4 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.3 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.2 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.1 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.15.0 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.5 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.4 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.3 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.2 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.1 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.14.0 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.13.7 app/components/avo/fields/boolean_group_field/edit_component.rb
avo-3.13.6 app/components/avo/fields/boolean_group_field/edit_component.rb