Sha256: cb37741a9566db039594fe89526876b8c26b888f63c81fd1412a39a6326d962e

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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'
        'fe/date_field_mmyy'
      else
        'fe/date_field'
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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