Class: Dima::Html::Field
- Includes:
- Init
- Defined in:
- lib/dima/html/field.rb
Overview
Field is used in a form.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#after ⇒ Object
element to be placed AFTER the field content.
-
#align ⇒ Object
text align: used for correct display in tables.
-
#before ⇒ Object
element to be placed BEFORE the field content.
-
#edit ⇒ Object
edit mode switch.
-
#form ⇒ Object
form holding this field.
-
#has_errors ⇒ Object
Returns the value of attribute has_errors.
-
#hint ⇒ Object
hint message.
-
#label ⇒ Object
label describes this field.
-
#required ⇒ Object
is this field required?.
-
#tooltip ⇒ Object
tooltip.
-
#url ⇒ Object
url property.
Instance Method Summary collapse
-
#after_node ⇒ Object
After node.
-
#before_node ⇒ Object
Before node.
- #edit? ⇒ Boolean
-
#empty_node ⇒ Object
Empty node.
-
#label_node ⇒ Object
Prepare label node for this field.
-
#options ⇒ Object
Additional properties.
-
#to_n ⇒ Object
Create html node for the field.
-
#url_node ⇒ Object
Url node.
-
#val ⇒ Object
Get current value of the field.
-
#val=(v) ⇒ Object
Set the value of the field.
- #validate ⇒ Object
-
#value_node ⇒ Object
Prepare content node.
Methods included from Init
Methods inherited from Element
Instance Attribute Details
#after ⇒ Object
element to be placed AFTER the field content
42 43 44 |
# File 'lib/dima/html/field.rb', line 42 def after @after end |
#align ⇒ Object
text align: used for correct display in tables
46 47 48 |
# File 'lib/dima/html/field.rb', line 46 def align @align end |
#before ⇒ Object
element to be placed BEFORE the field content
40 41 42 |
# File 'lib/dima/html/field.rb', line 40 def before @before end |
#edit ⇒ Object
edit mode switch
48 49 50 |
# File 'lib/dima/html/field.rb', line 48 def edit @edit end |
#form ⇒ Object
form holding this field
30 31 32 |
# File 'lib/dima/html/field.rb', line 30 def form @form end |
#has_errors ⇒ Object
Returns the value of attribute has_errors.
50 51 52 |
# File 'lib/dima/html/field.rb', line 50 def has_errors @has_errors end |
#hint ⇒ Object
hint message
36 37 38 |
# File 'lib/dima/html/field.rb', line 36 def hint @hint end |
#label ⇒ Object
label describes this field
32 33 34 |
# File 'lib/dima/html/field.rb', line 32 def label @label end |
#required ⇒ Object
is this field required?
38 39 40 |
# File 'lib/dima/html/field.rb', line 38 def required @required end |
#tooltip ⇒ Object
tooltip
34 35 36 |
# File 'lib/dima/html/field.rb', line 34 def tooltip @tooltip end |
#url ⇒ Object
url property
44 45 46 |
# File 'lib/dima/html/field.rb', line 44 def url @url end |
Instance Method Details
#after_node ⇒ Object
After node.
127 128 129 |
# File 'lib/dima/html/field.rb', line 127 def after_node Node.new(tag: 'span', attributes: { class: 'dim-after' }, text: self.after) if self.after end |
#before_node ⇒ Object
Before node.
122 123 124 |
# File 'lib/dima/html/field.rb', line 122 def before_node Node.new(tag: 'span', attributes: { class: 'dim-before' }, text: self.before) if self.before end |
#edit? ⇒ Boolean
72 73 74 |
# File 'lib/dima/html/field.rb', line 72 def edit? self.edit and not self.readonly end |
#empty_node ⇒ Object
Empty node.
110 111 112 |
# File 'lib/dima/html/field.rb', line 110 def empty_node Node.new(tag: 'span', attributes: { class: 'dim-empty' }, text: '(empty)') end |
#label_node ⇒ Object
Prepare label node for this field.
115 116 117 118 119 |
# File 'lib/dima/html/field.rb', line 115 def label_node unless @label == false Node.new(tag: 'div', attributes: { class: 'dim-label' }, text: @label) end end |
#options ⇒ Object
Additional properties.
68 69 70 |
# File 'lib/dima/html/field.rb', line 68 def @options ||= {} end |
#to_n ⇒ Object
Create html node for the field.
77 78 79 80 81 82 83 84 |
# File 'lib/dima/html/field.rb', line 77 def to_n field = Node.new(tag: 'div', attributes: { id: self.id, class: 'dim-field' }) field.add_class('dim-required') if required field.add_class('dim-error') if has_errors field << label_node field << value_node field end |
#url_node ⇒ Object
Url node.
132 133 134 135 136 137 138 139 140 |
# File 'lib/dima/html/field.rb', line 132 def url_node if self.url if self.url.is_a?(Proc) and self.model Node.new(tag: 'a', attributes: {href: self.url.call(self.model)}) else Node.new(tag: 'a', attributes: {href: self.url.to_s}) end end end |
#val ⇒ Object
Get current value of the field.
58 59 60 |
# File 'lib/dima/html/field.rb', line 58 def val @val end |
#val=(v) ⇒ Object
Set the value of the field.
63 64 65 |
# File 'lib/dima/html/field.rb', line 63 def val=(v) @val = v end |
#validate ⇒ Object
52 53 54 55 |
# File 'lib/dima/html/field.rb', line 52 def validate self.has_errors = false self.has_errors = true if self.required and Dima::Utils.empty?(@val) end |
#value_node ⇒ Object
Prepare content node.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dima/html/field.rb', line 87 def value_node content = Node.new(tag: 'div', attributes: { class: 'dim-value' }) if empty? and not self.edit? content << empty_node else content.add_class(align.to_s) if align content << before_node ## content + link node link_node = url_node if link_node and not self.edit link_node << main_content_node content << link_node else content << main_content_node end ## content << after_node content end content end |