Sha256: 7399e20acc868f2254000dabec9ed1d0e7b4a27e7b5c7b49aa36ef5b0f7281f4

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require "formalist/element"

module Formalist
  class Elements
    class CompoundField < Element
      def fill(input: {}, errors: {})
        children = self.children.map { |child|
          child.fill(input: input, errors: errors)
        }

        super(input: input, errors: errors, children: children)
      end

      # Converts the compound field into an abstract syntax tree.
      #
      # It takes the following format:
      #
      # ```
      # [:compound_field, [params]]
      # ```
      #
      # With the following parameters:
      #
      # 1. Custom element type (or `:compound_field` otherwise)
      # 2. Form element attributes
      # 3. Child form elements
      #
      # @see Formalist::Element::Attributes#to_ast "Form element attributes" structure
      #
      # @example
      #   compound_field.to_ast
      #   # => [:compound_field, [
      #     :content,
      #     :compound_field,
      #     [:object, []],
      #     [...child elements...],
      #   ]]
      #
      # @return [Array] the compound field as an abstract syntax tree.
      def to_ast
        [:compound_field, [
          type,
          Element::Attributes.new(attributes).to_ast,
          children.map(&:to_ast),
        ]]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formalist-0.9.0 lib/formalist/elements/compound_field.rb
formalist-0.8.0 lib/formalist/elements/compound_field.rb
formalist-0.7.0 lib/formalist/elements/compound_field.rb
formalist-0.6.0 lib/formalist/elements/compound_field.rb