Class: Formalist::Elements::Field
- Inherits:
-
Formalist::Element
- Object
- Formalist::Element
- Formalist::Elements::Field
- Defined in:
- lib/formalist/elements/field.rb
Direct Known Subclasses
CheckBox, DateField, DateTimeField, HiddenField, MultiSelectionField, MultiUploadField, NumberField, RadioButtons, RichTextArea, SearchMultiSelectionField, SearchSelectionField, SelectBox, SelectionField, TagsField, TextArea, TextField, UploadField
Instance Attribute Summary
Attributes inherited from Formalist::Element
#attributes, #children, #errors, #input, #name
Instance Method Summary collapse
- #fill(input: {}, errors: {}) ⇒ Object
-
#to_ast ⇒ Array
Converts the field into an abstract syntax tree.
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
12 13 14 15 16 17 |
# File 'lib/formalist/elements/field.rb', line 12 def fill(input: {}, errors: {}) super( input: input[name], errors: errors[name].to_a, ) end |
#to_ast ⇒ Array
Converts the field into an abstract syntax tree.
It takes the following format:
[:field, [params]]
With the following parameters:
- Field name
- Custom form element type (or
:field
otherwise) - Associated form input data
- Error messages
- Form element attributes
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/formalist/elements/field.rb', line 48 def to_ast # errors looks like this # {:field_name => [["pages is missing", "another error message"], nil]} [:field, [ name, type, input, errors, Element::Attributes.new(attributes).to_ast, ]] end |