Class: Formalist::Elements::Group

Inherits:
Formalist::Element show all
Defined in:
lib/formalist/elements/group.rb

Instance Attribute Summary

Attributes inherited from Formalist::Element

#attributes, #children, #errors, #input, #name

Instance Method Summary collapse

Methods inherited from Formalist::Element

#==, build, fill, #initialize, #type

Methods included from Formalist::Element::ClassInterface

#attribute, #attributes_schema, #type

Constructor Details

This class inherits a constructor from Formalist::Element

Instance Method Details

#fill(input: {}, errors: {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/formalist/elements/group.rb', line 8

def fill(input: {}, errors: {})
  children = self.children.map { |child|
    child.fill(input: input, errors: errors)
  }

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

#to_astArray

Converts the group into an abstract syntax tree.

It takes the following format:

[:group, [params]]

With the following parameters:

  1. Custom form element type (or :group otherwise)
  2. Form element attributes
  3. Child form elements

Examples:

group.to_ast
# => [:group, [
  :group,
  [:object, []],
  [...child elements...]
]]

Returns:

  • (Array)

    the group as an abstract syntax tree.

See Also:



41
42
43
44
45
46
47
# File 'lib/formalist/elements/group.rb', line 41

def to_ast
  [:group, [
    type,
    Element::Attributes.new(attributes).to_ast,
    children.map(&:to_ast),
  ]]
end