Skip to content

Commit

Permalink
Update forms_helper.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed May 31, 2024
1 parent ac30755 commit 0bdcbf6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/helpers/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,19 @@ def date_select_with_label(**args)
end
end

# The index arg is for multiple date_selects in a form
def date_select_opts(args = {})
obj = args[:object]
start_year = args[:start_year] || 20.years.ago.year
end_year = args[:end_year] || Time.zone.now.year
init_value = obj.try(&:when).try(&:year)
start_year = init_value if init_value && init_value < start_year
{ start_year: start_year,
end_year: end_year,
selected: obj.try(&:when) || Time.zone.today,
order: args[:order] || [:day, :month, :year] }
opts = { start_year: start_year,
end_year: end_year,
selected: obj.try(&:when) || Time.zone.today,
order: args[:order] || [:day, :month, :year] }
opts[:index] = args[:index] if args[:index].present?
opts
end

# Bootstrap number_field
Expand Down

0 comments on commit 0bdcbf6

Please sign in to comment.