Class: Formalist::ChildForms::ChildForm
- Inherits:
-
Element
- Object
- Element
- Formalist::ChildForms::ChildForm
show all
- Defined in:
- lib/formalist/child_forms/child_form.rb
Constant Summary
collapse
- DEFAULT_INPUT_PROCESSOR =
-> input { input }.freeze
Instance Attribute Summary
Attributes inherited from Element
#children, #errors, #input, #name
Instance Method Summary
collapse
Methods inherited from Element
#==, build, fill, #initialize, #type
#attribute, #attributes_schema, #type
Instance Method Details
#attributes ⇒ Object
18
19
20
|
# File 'lib/formalist/child_forms/child_form.rb', line 18
def attributes
super.merge(form: form_attribute_ast)
end
|
#fill(input: {}, errors: {}) ⇒ Object
14
15
16
|
# File 'lib/formalist/child_forms/child_form.rb', line 14
def fill(input: {}, errors: {})
super(input: form_input_ast(input), errors: errors.to_a)
end
|
22
23
24
|
# File 'lib/formalist/child_forms/child_form.rb', line 22
def form_attribute_ast
@attributes[:form].to_ast
end
|
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/formalist/child_forms/child_form.rb', line 26
def form_input_ast(data)
validation = @attributes[:schema].(data)
input = @attributes[:input_processor].(validation.to_h)
@attributes[:form].fill(input: input, errors: validation.errors.to_h).to_ast
end
|
#to_ast ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/formalist/child_forms/child_form.rb', line 38
def to_ast
[:child_form, [
name,
type,
input,
Element::Attributes.new(attributes).to_ast,
]]
end
|