Class: DynamicFieldsets::DatetimeField
- Defined in:
- app/models/dynamic_fieldsets/datetime_field.rb
Overview
Creates datetime tags on a form
The datetime tag currently defaults to the current time if nothing is set with the year range starting 70 years in the past
The value of the input is stored as a string so costly Time.parse calls are used to parse the string This may have to be changed in the future
Instance Method Summary collapse
-
#form_partial_locals(args) ⇒ Hash
Includes information used in the date_options argument (third) on the date select helper.
-
#get_datetime_or_today(value) ⇒ Time
Returns the current value if set, then the default value if set, then the current time as a Time object.
Methods inherited from Field
#collect_default_values, #collect_field_records_by_fsa_and_fsc, descendant_collection, descendants, #display_type, #form_footer_partial, #form_header_partial, #form_partial, #get_value_for_show, #get_values_using_fsa_and_fsc, #has_defaults?, #html_attribute_hash, #in_use?, #show_footer_partial, #show_header_partial, #show_partial, #show_partial_locals, #update_field_records, #use_form_footer_partial?, #use_form_header_partial?, #use_show_footer_partial?, #use_show_header_partial?, #uses_field_options?
Instance Method Details
#form_partial_locals(args) ⇒ Hash
Includes information used in the date_options argument (third) on the date select helper
26 27 28 29 30 31 32 33 |
# File 'app/models/dynamic_fieldsets/datetime_field.rb', line 26 def form_partial_locals(args) output = super output[:date_options] = { :start_year => Time.now.year - 70, :default => get_datetime_or_today(args[:value]) } return output end |
#get_datetime_or_today(value) ⇒ Time
Returns the current value if set, then the default value if set, then the current time as a Time object
14 15 16 17 18 19 20 21 |
# File 'app/models/dynamic_fieldsets/datetime_field.rb', line 14 def get_datetime_or_today(value) default_time = value_or_default_for_form(value) if default_time.empty? return Time.now else return Time.parse(default_time) end end |