Rails 4 date_field, min and max year?
I am trying to set the maximum year value for my form using the rails 4 '' date_field '' method because the user can enter years in excess of 4 digits.
I'm trying to use it like this, but it doesn't seem to have any effect.
<%= f.date_field :date, style: "height: 30px", min: Time.now.year , max: Time.now.year + 84 %>
source to share
This is how I did it:
<%= f.date_field :date, min: Date.now(1994, 07, 03), max: Date.today %>
I have limited the minimum and maximum date that the user could use with the built-in collector using methods in the Ruby Date class. The only problem is that it is not dynamic. And in regards to your question about year validation, I believe that browsers do this automatically if it detects an input field with a date type (like <input id="user_date" min="1994-07-03" name="user[birthdate]" type="date">
) even before the user submits the form. Hope this helped.
source to share