Sha256: 1b68cc60264a4dc4bd96b45b721f77e5885eaec4dbd799ad8234dc09b44bb351

Contents?: true

Size: 796 Bytes

Versions: 18

Compression:

Stored size: 796 Bytes

Contents

module Avo
  module Fields
    class BooleanGroupField < Field
      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

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

      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
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
avo-0.4.10 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.9 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.8 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.7 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.6 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.5 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.4 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.3 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.2 lib/avo/app/fields/boolean_group_field.rb
avo-0.4.1 lib/avo/app/fields/boolean_group_field.rb
avo-0.3.2 lib/avo/app/fields/boolean_group_field.rb
avo-0.3.1 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.5 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.4 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.3 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.2 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.1 lib/avo/app/fields/boolean_group_field.rb
avo-0.2.0 lib/avo/app/fields/boolean_group_field.rb