Class: Dima::Html::NumberField

Inherits:
SimpleField show all
Includes:
TextEditor
Defined in:
lib/dima/html/field.rb

Overview

Display number.

Instance Attribute Summary collapse

Attributes inherited from SimpleField

#height, #klass, #lambda, #model, #name, #readonly, #width

Attributes inherited from Field

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

Instance Method Summary collapse

Methods included from TextEditor

#editor

Methods inherited from SimpleField

#<<, #>>, #empty?, #main_content_node, #readonly?

Methods inherited from Field

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

Methods inherited from Element

#id, #id=

Constructor Details

#initialize(h = {}) ⇒ NumberField

Returns a new instance of NumberField.



303
304
305
306
# File 'lib/dima/html/field.rb', line 303

def initialize(h = {})
  super(h)
  self.align = 'right' unless self.align
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter.



300
301
302
# File 'lib/dima/html/field.rb', line 300

def delimiter
  @delimiter
end

#precisionObject

Returns the value of attribute precision.



299
300
301
# File 'lib/dima/html/field.rb', line 299

def precision
  @precision
end

#separatorObject

Returns the value of attribute separator.



301
302
303
# File 'lib/dima/html/field.rb', line 301

def separator
  @separator
end

Instance Method Details

#simple_value_nodeObject



308
309
310
311
312
313
314
315
316
317
# File 'lib/dima/html/field.rb', line 308

def simple_value_node
  if self.edit?
    editor(val: self.val.to_s, type: 'dim-number', width: width)
  else
    frmtValue = Dima::Utils.number_format(self.val, precision: self.precision, delimiter: self.delimiter, separator: self.separator)
    node = Node.new(tag: 'span', attributes: { class: 'dim-main-content dim-number' })
    node << Node.new(tag: 'code', text: frmtValue)
    node
  end
end

#value_from_text(val) ⇒ Object



319
320
321
322
323
324
325
# File 'lib/dima/html/field.rb', line 319

def value_from_text(val)
  if precision == 0
    self.val = val.to_i
  else
    self.val = val.to_f
  end
end