0

Is there a way in rails to override default date input in form? In html form I get date input as drop down menu. The thing is for year it only shows year from 2008 to 2018. How can I make it let me enter any year I want, but keep month and day as dropbox? I tried in html form use type="date", but nothing changes.

What is the best way to modify date input format in rails (and html/javascript if it needs to be changed there too)?

Andrius
  • 19,658
  • 37
  • 143
  • 243
  • Maybe [this post](http://stackoverflow.com/questions/3231772/how-can-i-modify-the-input-type-of-the-rails-datetime-select-helper) can help you to develope your own helper. – fabi Oct 22 '13 at 15:37

2 Answers2

1

Your could write your own helper:

def date_year_text_field(object_name, method)
  html = select_day(Date.today, :field_name => "#{object_name}[#{method}(3i)]")
  html << select_month(Date.today, :field_name => "#{object_name}[#{method}(2i)]")
  html << text_field_tag("#{object_name}[#{method}(1i)]", Date.today.year.to_s, :length => 4)
end
fabi
  • 53
  • 5
0

You can use the start_year and end_year option. By default the range is current_year - 5 and current_year + 5

date_select("post", "updated_on", start_year: 1995, end_year: 2013)

Read the documentation for more options

usha
  • 28,973
  • 5
  • 72
  • 93