I have a form that I've made using simple_form, one of the fields in the form is a datetime. I'd like to limit it so that users can only select dates that are after the datetime as of now so they can't create records for the past.
I've experimented doing this with validations but I'd just like to limit the form options instead. I limited the hour range to what I wanted but can't find something similar for days.
The form for the event
<%= simple_form_for @event do |f| %>
<%-# Form input fields -%>
<%= f.input :name, label: 'Title' %>
<%= f.input :event_date, minute_step: 15, start_hour: 7, end_hour: 21 %>
<%= f.input :body %>
<%= f.submit 'Submit' , :class => "btn btn-primary" %>
<% end %>
For Rails 4:
For rails 4, there is the date_field
helper which can accept both min
and max
values.
You can use this to set the value range wanted. so, you will have something like:
<%= f.date_field : event_date, min: Date.today %>
You can get more information about this from the documentation here
Old answer:
You can specify the :start_year
option, as seen on the documentation here:
:start_year - Set the start year for the year select. Default is Date.today.year - 5 if you are creating new record. While editing existing record, :start_year defaults to the current selected year minus 5.
So, in this case, what you will have to do is to specify the :start_year
as the current year.
Hope this answers your question.