Class: EasyAdmin::Layouts::Nodes::FieldNode

Inherits:
BaseNode
  • Object
show all
Defined in:
lib/easy_admin/layouts/nodes/field_node.rb

Overview

Node representing a field to be rendered

Instance Attribute Summary

Attributes inherited from BaseNode

#attributes, #children, #metadata, #visible_if

Instance Method Summary collapse

Methods inherited from BaseNode

#[], #[]=, #accept, #add_child, #children?, #node_type, #visible?

Constructor Details

#initialize(name, attributes = {}) ⇒ FieldNode

Returns a new instance of FieldNode.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 6

def initialize(name, attributes = {})
  super(attributes)
  @field_name = name.to_sym
  @attributes[:as] ||= nil # Field type override
  @attributes[:label] ||= nil # Custom label
  @attributes[:readonly] ||= false
  @attributes[:required] ||= false
  @attributes[:hint] ||= nil
  @attributes[:placeholder] ||= nil
  @attributes[:wrapper_class] ||= nil
end

Instance Method Details

#field_nameObject



18
19
20
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 18

def field_name
  @field_name
end

#field_optionsObject

Get all field options for rendering



51
52
53
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 51

def field_options
  @attributes.except(:visible_if, :metadata)
end

#field_typeObject



22
23
24
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 22

def field_type
  @attributes[:as]
end

#hintObject



38
39
40
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 38

def hint
  @attributes[:hint]
end

#labelObject



26
27
28
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 26

def label
  @attributes[:label]
end

#placeholderObject



42
43
44
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 42

def placeholder
  @attributes[:placeholder]
end

#readonly?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 30

def readonly?
  @attributes[:readonly]
end

#required?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 34

def required?
  @attributes[:required]
end

#wrapper_classObject



46
47
48
# File 'lib/easy_admin/layouts/nodes/field_node.rb', line 46

def wrapper_class
  @attributes[:wrapper_class]
end