Introduction
We posted the ActiveCalendar project a couple of months ago (incidentally it was the first post on this blog as well). Since then, the response has been great. It seems like people are actually using it. For that, thank you, we’re very happy people have found this code useful. Some of you have been kind enough to post comments and questions. In response, we’ve been making incremental changes (hopefully improvements) to the code base. Rather than continue to detail them in the comments of the original post, I decided roll them up and describe them here.
validates_as_date
The plugin originally left the text fields uneditable, so the only way to edit the date was through the calendar. It became clear that this wasn’t ideal. Not only is it sometimes quicker to type your date out, as Art pointed out, once you selected a date, there was no way to blank it out. To alleviate this problem, we simply made the text fields editable. However, this create another potential problem, invalid dates. This is where validates_as_date was born.
To validate your dates, add the following code to your model:
That’s it! validates_as_date is a slight adaptation of the code snippet by Stuart Rackham found here.
Add Dynarch Parameters
The Dynarch Calendar is very flexible… up until recently our plugin was not. Many of you wanted to access the flexibility, but were unable to. We recently checked in some code that allows you to pass options to the date_select and datetime_select methods and have the options passed into Dynarch’s Calendar.
For instance, Mike Figley wanted to use the date status function, which allows you to specify some dates as special. Now you can, so using the example from Dynarch’s documentation, you could now use ActiveCalendar to highlight certain dates
Notice the last line, now any extra options are passed directly to the Calendar.setup method.
Included in the list of possible options you can pass is ifFormat, which is the date format ActiveCalendar uses. Uma Shankar Ladha wanted to be able to just select a month and year, I’m not sure if ActiveCalendar is the best way to do that, but you could use the following code to make sure that no matter what date the user selects, your program would only get the month and year:
That format is used by both Ruby and Javascript for displaying dates, so you have to make sure that your format is parsable by both Ruby and the Calendar Javascript. Luckily their formats are extremely similar. The following list contains all the tags recognizable by both:
In case you are interested the Ruby formats you can’t use are:
And the Dynarch codes you can’t use are:
Also note that if you change the formatting, validates_as_date will not work properly. I plan on fixing that in the future.
Overridable IDs
The last change worth mentioning (there have been others) was contributed by Peer Allen. He was using ActiveCalendar in conjunction with AJAX and needed to override the id property. His code allows the programmer to specify the name and id of the html entries used by ActiveCalendar. Thanks Peer!
Conclusion
Thank you all for using and contributing to ActiveCalendar. Please let us know how you’re using it and what problems you’ve encountered.