Class: Forma::DateField

Inherits:
SimpleField show all
Defined in:
lib/forma/field.rb

Overview

Date feild.

Instance Attribute Summary collapse

Attributes inherited from Field

#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #url, #value, #width

Instance Method Summary collapse

Methods inherited from SimpleField

#errors, #has_errors?, #value

Methods inherited from Field

#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html

Methods included from Html

attr, el

Methods included from Utils

extract_value, #simple_value, singular_name

Constructor Details

#initialize(h = {}) ⇒ DateField

Returns a new instance of DateField.



336
337
338
339
340
# File 'lib/forma/field.rb', line 336

def initialize(h = {})
  h = h.symbolize_keys
  @formatter = h[:formatter]
  super(h)
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



334
335
336
# File 'lib/forma/field.rb', line 334

def formatter
  @formatter
end

Instance Method Details

#edit_element(val) ⇒ Object



346
347
348
349
350
351
352
353
354
# File 'lib/forma/field.rb', line 346

def edit_element(val)
  el('input', attrs: {
    name: parameter_name,
    type: 'text',
    value: val.to_s,
    autofocus: @autofocus,
    style: { width: ("#{width}px" if width.present?) }
  })
end

#view_element(val) ⇒ Object



342
343
344
# File 'lib/forma/field.rb', line 342

def view_element(val)
  el('span', text: val.localtime.strftime(formatter || Forma.config.date.formatter))
end