A simple example on to disable dates

90 views
Skip to first unread message

gabs

unread,
Nov 18, 2008, 5:56:46 AM11/18/08
to Ruby on Rails: DHTML Calendar
Just figured this might be of interest for others,
here's how you can disable all dates in the calendar prior to today.

If the dateStatusHandler functions returns true the date will be
disabled, if it returns false nothing happens, if it returns a string,
the string will become the .css class for that date. You can use the
last part to mark special dates in you calendar. If anyone wants an
example on how to do that, I'll be happy to provide one.

anyways, just paste everything below in your view (currently theres a
bug in the helper, so if it don't work try to replace :dateStatusFunc
with :DateStatusFunc ):

<% javascript_tag do -%>
var dateStatusHandler = function(date, y, m, d) {
var yesterday = new Date();
yesterday.setDate(yesterday.getDate()-1)
if (date <= yesterday) return true;
else return false;
}
<% end -%>

<%= calendar_box 'booking_request', 'date_start',
{ :class => 'date',
:field_title => 'Check date',
:button_image => 'calendar.gif',
:form_name => '',
:button_title => 'Show Calendar' },
{ :firstDay => 1,
:range => [2008, 2010],
:step => 1,
:showOthers => true,
:cache => true,
:weekNumber => true,
:timeFormat => "24",
:showsTime => false,
:dateStatusFunc => "dateStatusHandler" } %>

Reply all
Reply to author
Forward
0 new messages