Class: Fe::DateField
Instance Attribute Summary
Attributes inherited from Question
#answers
Attributes inherited from Element
#old_id
Instance Method Summary
collapse
Methods inherited from Question
#check_answer_sheet_matches_set_response_answer_sheet, #default_label?, #delete_file, #has_response?, #locked?, #responses, #save_file, #save_response, #set_response
Methods inherited from Element
#all_elements, #conditional_answers, #conditional_match, #content, create_from_import, #css_classes, #duplicate, #export_hash, #export_to_yaml, #has_response?, #hidden?, #hidden_by_choice_field?, #hidden_by_conditional?, #label, #limit, #matches_filter, max_label_length, #page_id, #pages_on, #position, #previous_element, #question?, #required?, #reuseable?, #set_conditional_element, #set_position, #tooltip, #update_any_previous_conditional_elements, #update_page_all_element_ids, #visibility_affecting_element_ids, #visibility_affecting_questions, #visible?
Instance Method Details
#display_response(answer_sheet = nil) ⇒ Object
32
33
34
|
# File 'app/models/fe/date_field.rb', line 32
def display_response(answer_sheet = nil)
return format_date_response(answer_sheet)
end
|
36
37
38
39
40
|
# File 'app/models/fe/date_field.rb', line 36
def format_date_response(answer_sheet = nil)
r = response(answer_sheet)
r = r.strftime("%Y-%m-%d") unless r.blank?
r
end
|
#ptemplate ⇒ Object
which view to render this element?
43
44
45
46
47
48
49
|
# File 'app/models/fe/date_field.rb', line 43
def ptemplate
if self.style == 'mmyy'
'fe/date_field_mmyy'
else
'fe/date_field'
end
end
|
#response(answer_sheet = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/models/fe/date_field.rb', line 14
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
|
#validation_class(answer_sheet = nil, page = nil) ⇒ Object
6
7
8
9
10
11
12
|
# File 'app/models/fe/date_field.rb', line 6
def validation_class(answer_sheet = nil, page = nil)
if self.style == 'mmyy'
'validate-selection ' + super
else
'validate-date ' + super
end
end
|