Class: CustomAttributes::DateFieldType
- Inherits:
-
Unbounded
show all
- Includes:
- Singleton
- Defined in:
- lib/custom_attributes/field_types/date_field_type.rb
Instance Method Summary
collapse
Methods inherited from FieldType
#after_save_custom_value, available_types, #before_custom_field_save, #cast_custom_value, #cast_value, find, #label, #name, #possible_custom_value_options, #possible_values_options, #set_custom_field_value, #validate_custom_field, #validate_custom_value, #value_from_keyword
Instance Method Details
#cast_single_value(_custom_field, value, _customized = nil) ⇒ Object
5
6
7
8
9
|
# File 'lib/custom_attributes/field_types/date_field_type.rb', line 5
def cast_single_value(_custom_field, value, _customized = nil)
value.to_date
rescue
nil
end
|
#edit_tag(view, tag_id, tag_name, custom_value, options = {}) ⇒ Object
23
24
25
26
|
# File 'lib/custom_attributes/field_types/date_field_type.rb', line 23
def edit_tag(view, tag_id, tag_name, custom_value, options = {})
view.date_field_tag(tag_name, custom_value.value, options.merge(id: tag_id, size: 10)) +
view.calendar_for(tag_id)
end
|
#validate_single_value(_custom_field, value, _customizable = nil) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/custom_attributes/field_types/date_field_type.rb', line 11
def validate_single_value(_custom_field, value, _customizable = nil)
if value =~ /^\d{4}-\d{2}-\d{2}$/ && (begin
value.to_date
rescue
false
end)
[]
else
[::I18n.t('activerecord.errors.messages.not_a_date')]
end
end
|