method
date_or_time_select
v2.1.0 -
Show latest stable
-
0 notes -
Class: ActionView::Helpers::InstanceTag
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- What's this?
date_or_time_select(options, html_options = {})
private
Hide source
# File actionpack/lib/action_view/helpers/date_helper.rb, line 614 def date_or_time_select(options, html_options = {}) defaults = { :discard_type => true } options = defaults.merge(options) datetime = value(object) datetime ||= default_time_from_options(options[:default]) unless options[:include_blank] position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 } order = (options[:order] ||= [:year, :month, :day]) # Discard explicit and implicit by not being included in the :order discard = {} discard[:year] = true if options[:discard_year] or !order.include?(:year) discard[:month] = true if options[:discard_month] or !order.include?(:month) discard[:day] = true if options[:discard_day] or discard[:month] or !order.include?(:day) discard[:hour] = true if options[:discard_hour] discard[:minute] = true if options[:discard_minute] or discard[:hour] discard[:second] = true unless options[:include_seconds] && !discard[:minute] # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid # (otherwise it could be 31 and february wouldn't be a valid date) if datetime && discard[:day] && !discard[:month] datetime = datetime.change(:day => 1) end # Maintain valid dates by including hidden fields for discarded elements [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) } # Ensure proper ordering of :hour, :minute and :second [:hour, :minute, :second].each { |o| order.delete(o); order.push(o) } date_or_time_select = '' order.reverse.each do |param| # Send hidden fields for discarded elements once output has started # This ensures AR can reconstruct valid dates using ParseDate next if discard[param] && date_or_time_select.empty? date_or_time_select.insert(0, self.send("select_#{param}", datetime, options_with_prefix(position[param], options.merge(:use_hidden => discard[param])), html_options)) date_or_time_select.insert(0, case param when :hour then (discard[:year] && discard[:day] ? "" : " — ") when :minute then " : " when :second then options[:include_seconds] ? " : " : "" else "" end) end date_or_time_select end