I want to prevent past dates from being selected when I have a date entered from the calendar. Date type is used for the column of the model to be saved. Use form_with to create a form in the view.
ruby 2.6.5 Rails 6.0.3.3
ruby:index.html.erb
<%= form_with model: @order, url: item_order_path, local: true do |f|%>
<%= f.date_field :start_date, class:"order-date-form %>
<% end %>
You can display the calendar and select the date.
However, at present, you can also select past dates.
Add a description to solve this.
ruby:index.html.erb
<%= form_with model: @order, url: item_order_path, local: true do |f|%>
<%= f.date_field :start_date, class:"order-date-form, min: Date.current %>
<% end %>
The calendar is displayed in the same way, but past dates can no longer be selected.
"Date" is provided by Active_support and seems to be available by default. "Date.current" is recommended instead of "Date.today".
Click here for details Rails Guide
Try adding each to prevent with validation or controller.
Recommended Posts