I am using the jQuery UI DatePicker for an event app. Very often, I will have say an event that runs every Tuesday all year.
Now, the datepicker allows people to register for attendance reasons, so I would like to allow people to register for past dates, however, when the page loads, I want it to show the current month. Right now, it shows the start date of the event:
<%
event == event
date_to_use_for_max_dates = event.end_date.nil? ? event.start_date :
event.end_date
date_to_use_for_max_dates = date_to_use_for_max_dates > Date.today ?
date_to_use_for_max_dates : Date.today
event_dates = event.get_occuring_dates(event.start_date,
date_to_use_for_max_dates.advance(:years => EventRsvp::REGISTRATION_MAX_CHECK_YEARS))
min_date = [event_dates.first.strftime("%m"), event_dates.first.strftime("%d"),
event_dates.first.strftime("%Y")]
max_date = [event_dates.last.strftime("%m"), event_dates.last.strftime("%d"),
event_dates.last.strftime("%Y")]
event_dates_for_the_month = event_dates.collect{|d| d if d.month ==
event_dates.first.month }.compact.collect{|d| [d.strftime("%m"), d.strftime("%d"),
d.strftime("%Y")] }
registered_dates = event.get_registered_dates(current_user).collect{|d|
[d.strftime("%m"), d.strftime("%d"), d.strftime("%Y")] }
url_for_registration_details ||= registration_details_for_day_event_path(event)
%>
and then the actual calendar:
<div id="event-calendar" data-event-name="<%= event.name %>" data-dates-url="
<%= occuring_dates_event_path(event) %>" data-registrations-url="<%=
url_for_registration_details %>" data-min-date="<%= min_date %>"
data-max-date="<%= max_date %>" data-event-dates="<%= event_dates_for_the_month
%>" data-registered-dates="<%= registered_dates %>"></div>
I tried changing the event dates to start today, but then someone can’t register for events in the past.
Any ideas?
You should be able to set the default date with the
defaultDateoption, though it’s a bit hard to tell if this would actually work in your setup. Is there any javascript code you call to trigger the datepicker?