class Formalist::Elements::Attr
Public Instance Methods
fill(input:, errors:)
click to toggle source
Calls superclass method
Formalist::Element::fill
# File lib/formalist/elements/attr.rb, line 8 def fill(input:, errors:) input = input[name] || {} errors = errors[name] || {} children = self.children.map { |child| child.fill(input: input, errors: errors) } super(input: input, errors: errors, children: children) end
to_ast()
click to toggle source
Converts the attribute into an abstract syntax tree.
It takes the following format:
“‘
- :attr, [params]
-
“‘
With the following parameters:
-
Attribute name
-
Custom element type (or ‘:attr` otherwise)
-
Error messages
-
Form
element attributes -
Child form elements
@see
Formalist::Element::Attributes#to_ast
“Form element attributes” structure@example “metadata” attr
attr.to_ast # => [:attr, [ :metadata, :attr, ["metadata is missing"], [:object, []], [...child elements...] ]]
@return [Array] the attribute as an abstract syntax tree.
-
# File lib/formalist/elements/attr.rb, line 48 def to_ast local_errors = errors.is_a?(Array) ? errors : [] [:attr, [ name, type, local_errors, Element::Attributes.new(attributes).to_ast, children.map(&:to_ast), ]] end