class Forma::DateField

Date feild.

Attributes

formatter[R]

Public Class Methods

new(h = {}) click to toggle source
Calls superclass method Forma::SimpleField::new
# File lib/forma/field.rb, line 332
def initialize(h = {})
  h = h.symbolize_keys
  @formatter = h[:formatter]
  @@date_counter ||= 0
  @@date_counter += 1
  @date_counter = @@date_counter
  super(h)
end

Public Instance Methods

edit_element(val) click to toggle source
# File lib/forma/field.rb, line 346
def edit_element(val)
  input_id = "ff-date-#{@date_counter}"
  val = Date.strptime(val) if (val.present? and val.is_a?(String)) rescue nil
  el('div', children: [
    el('input', attrs: {
      id: input_id,
      name: parameter_name,
      value: val.to_s,
      type: 'hidden'
    }),
    el('input', attrs: {
      class: 'ff-date',
      type: 'text',
      value: (val.strftime('%d-%b-%Y') if val.present?),
      autofocus: @autofocus,
      style: { width: "#{width || 100}px" },
      'data-altfield' => input_id,
    })
  ])
end
view_element(val) click to toggle source
# File lib/forma/field.rb, line 341
def view_element(val)
                    val = val.respond_to?(:localtime) ? val.localtime : val
  el('span', text: val.strftime(formatter || Forma.config.date.formatter))
end