TangoKilo
TangoKilo

Reputation: 1785

Rails Date Select Parameters

I'm using a date select in a rails 3 form.

<%=f.date_select :date %>

I would like to restrict the dates so that you can only pick dates that fall on a Sunday. Is there any way of going about doing this?

I'm also trying to stop dates which have already passed from appearing.

Thanks for any help in advance!

Upvotes: 0

Views: 461

Answers (2)

Matzi
Matzi

Reputation: 13925

Rails date_select field generates three dropdown to select the parts of the date. There is no chanche, that you modify for example the month, and the day will still be sunday.

You must write some js magic to enforce such a role, or find an already existing datepicker and limit it. Or alternatively, you let the user to select a week, and calculate the exact date of sunday from that.

Upvotes: 1

TangoKilo
TangoKilo

Reputation: 1785

Ok having studied this out a bit further I don't think this is possible due to the format of the date_select field. The closest I can get is

<%=f.date_select :date, start_year: Time.now.year %>

so that at least you can't select dates from previous years. I've implemented the restriction on days and months that have past by setting up the view to automatically delete records that aren't relevant:

<% if(service.date < Date.today) %>
  <% service.destroy %>
<% end %> 

Not perfect but does the job in my case.

Upvotes: 0

Related Questions