Sha256: 687b0fed45646839976ccbf20cbe0bb4b53989367abb78bf7a850fced2fe75e2

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# DateField
# - a question that provides a calendar/date picker
module Fe
  class DateField < Question

    def validation_class(answer_sheet = nil)
      if self.style == 'mmyy'
        'validate-selection ' + super
      else
        'validate-date ' + super
      end
    end

    def response(answer_sheet = nil)
      r = super
      return nil if r.blank?
      begin
        if r.is_a?(String)
          parts = r.split('/')
          if parts.length == 3
            r = Time.mktime(parts[2], parts[0], parts[1])
          else
            r = Time.parse(r)
          end
        end
      rescue ArgumentError
        r = ''
      end
      r
    end

    def display_response(answer_sheet = nil)
      return format_date_response(answer_sheet)
    end

    def format_date_response(answer_sheet = nil)
      r = response(answer_sheet)
      r = r.strftime("%m/%d/%Y") unless r.blank?
      r
    end

    # which view to render this element?
    def ptemplate
      if self.style == 'mmyy'
        'date_field_mmyy'
      else
        'date_field'
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fe-0.0.3 app/models/fe/date_field.rb