Class: Avo::Fields::BooleanGroupField

Inherits:
Field
  • Object
show all
Defined in:
lib/avo/app/fields/boolean_group_field.rb

Instance Attribute Summary

Attributes inherited from Field

#block, #component, #computable, #default, #format_using, #help, #id, #is_array_param, #is_object_param, #name, #null_values, #nullable, #placeholder, #readonly, #required, #sortable, #updatable

Attributes included from FieldExtensions::VisibleOnDifferentViews

#show_on_create, #show_on_edit, #show_on_index, #show_on_show

Instance Method Summary collapse

Methods inherited from Field

#database_id, #fetch_for_action, #fetch_for_resource, #has_own_panel?, #resolve_attribute

Methods included from FieldExtensions::HasFieldName

#field_name, #field_name_attribute, #get_field_name

Methods included from FieldExtensions::VisibleOnDifferentViews

#except_on, #hide_on, #only_on, #show_on

Constructor Details

#initialize(name, **args, &block) ⇒ BooleanGroupField

Returns a new instance of BooleanGroupField.



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

def initialize(name, **args, &block)
  @defaults = {
    component: 'boolean-group-field',
    computable: true,
  }

  super(name, **args, &block)

  @is_object_param = true

  @options = args[:options].present? ? args[:options] : {}
end

Instance Method Details

#fill_field(model, key, value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/avo/app/fields/boolean_group_field.rb', line 23

def fill_field(model, key, value)
  return model unless value.is_a? ActionController::Parameters

  new_value = {}

  value.each do |key, value|
    new_value[key] = ActiveModel::Type::Boolean.new.cast value
  end

  model[id] = new_value

  model
end

#hydrate_field(fields, model, resource, view) ⇒ Object



17
18
19
20
21
# File 'lib/avo/app/fields/boolean_group_field.rb', line 17

def hydrate_field(fields, model, resource, view)
  {
    options: @options,
  }
end