Class: Dima::Html::DateField

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

Overview

Display date.

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 included from Init

#initialize

Methods inherited from Element

#id, #id=

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



332
333
334
# File 'lib/dima/html/field.rb', line 332

def formatter
  @formatter
end

Instance Method Details

#simple_value_nodeObject



334
335
336
337
338
339
340
341
# File 'lib/dima/html/field.rb', line 334

def simple_value_node
  frmtValue = self.val.strftime(self.formatter || Dima.config.date.formatter) if self.val
  if self.edit?
    editor(val: frmtValue, type: 'dim-date', width: width)
  else
    Node.new(tag: 'span', attributes: { class: 'dim-main-content dim-date' }, text: frmtValue)
  end
end

#value_from_text(val) ⇒ Object



343
344
345
# File 'lib/dima/html/field.rb', line 343

def value_from_text(val)
  self.val = Date.strptime(val, (self.formatter || Dima.config.date.formatter)) rescue nil
end