Class: DynamicFieldsets::DateField
- Defined in:
- app/models/dynamic_fieldsets/date_field.rb
Overview
Creates date tags on a form
The date tag currently defaults to the current date 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 Date.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_date_or_today(value) ⇒ Date
Returns the current value if set, then the default value if set, then the current date as a Date 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
27 28 29 30 31 32 33 34 |
# File 'app/models/dynamic_fieldsets/date_field.rb', line 27 def form_partial_locals(args) output = super output[:date_options] = { :start_year => Time.now.year - 70, :default => get_date_or_today(args[:value]) } return output end |
#get_date_or_today(value) ⇒ Date
Returns the current value if set, then the default value if set, then the current date as a Date object
14 15 16 17 18 19 20 21 22 |
# File 'app/models/dynamic_fieldsets/date_field.rb', line 14 def get_date_or_today(value) default_date = value_or_default_for_form(value) if default_date.empty? return Date.today else # not sure why Date.parse doesn't work here return Time.parse(default_date) end end |