Class: Dima::Html::SimpleField

Inherits:
Field show all
Defined in:
lib/dima/html/field.rb

Overview

Simple field has a name associated with it. Using this name we can associate values from a model.

Instance Attribute Summary collapse

Attributes inherited from Field

#after, #align, #before, #edit, #form, #has_errors, #hint, #label, #required, #tooltip, #url

Instance Method Summary collapse

Methods inherited from Field

#after_node, #before_node, #edit?, #empty_node, #label_node, #options, #to_n, #url_node, #val, #val=, #validate, #value_node

Methods included from Init

#initialize

Methods inherited from Element

#id, #id=

Instance Attribute Details

#heightObject

Returns the value of attribute height.



149
150
151
# File 'lib/dima/html/field.rb', line 149

def height
  @height
end

#klassObject

Returns the value of attribute klass.



152
153
154
# File 'lib/dima/html/field.rb', line 152

def klass
  @klass
end

#lambdaObject

Returns the value of attribute lambda.



148
149
150
# File 'lib/dima/html/field.rb', line 148

def lambda
  @lambda
end

#modelObject

Returns the value of attribute model.



151
152
153
# File 'lib/dima/html/field.rb', line 151

def model
  @model
end

#nameObject

Returns the value of attribute name.



147
148
149
# File 'lib/dima/html/field.rb', line 147

def name
  @name
end

#readonlyObject

Returns the value of attribute readonly.



150
151
152
# File 'lib/dima/html/field.rb', line 150

def readonly
  @readonly
end

#widthObject

Returns the value of attribute width.



149
150
151
# File 'lib/dima/html/field.rb', line 149

def width
  @width
end

Instance Method Details

#<<(v) ⇒ Object

Initialize this field from a model.

The field can be initialized from a hash too.



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/dima/html/field.rb', line 157

def << (v)
  if v and v.is_a?(Hash)
    update_from_hash(v)
  else
    self.model = v
    if self.lambda
      self.val = self.lambda.call(v) rescue nil
    elsif self.name
      self.val = Dima::Utils.get(v, self.name) rescue nil
    end
  end
end

#>>(v) ⇒ Object



170
171
172
# File 'lib/dima/html/field.rb', line 170

def >> (v)
  Dima::Utils.set(v, self.name, self.val) if self.name and not self.readonly?
end

#empty?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/dima/html/field.rb', line 180

def empty?
  Dima::Utils.empty?(self.val)
end

#main_content_nodeObject



174
175
176
177
178
# File 'lib/dima/html/field.rb', line 174

def main_content_node
  n = simple_value_node
  n.add_class(self.klass) if self.klass
  n
end

#readonly?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/dima/html/field.rb', line 184

def readonly?
  self.readonly
end