YUI Calendar: Minimum / Maximum Dates

Setting up the Calendar

Calendar can be easily configured to prevent users from being able to select dates before and after given minimum and maximum dates. For this tutorial, it is assumed that you are starting with the basic Calendar (outlined in the Quickstart Tutorial). The setup for the basic Calendar looks like this:

Enabling the minimum and maximum date features is as easy as adding additional arguments to the constructor's configuration object. In this tutorial, we will be working with three different configuration properties: pagedate, mindate and maxdate. In brief, here is a description of these properties and what they do:

  • pagedate - Specifies the month/year of the Calendar's initial view. For example, setting a value of "1/2006" would set the Calendar to January 2006.
  • mindate - Specifies the minimum selectable date for the Calendar. All dates before the minimum date will be grayed out. The value can be specified as a JavaScript Date object or as a string (e.g. "1/25/2007").
  • maxdate - Specifies the maximum selectable date for the Calendar. All dates after the maximum date will be grayed out. The value can be specified as a JavaScript Date object or as a string (e.g. "1/25/2007").

Of course, you can specify these properties independently for different results. For instance, if you only wanted users to be able to select days following August 2, 2006, you would set the mindate property to "8/2/2006" and no dates prior would be selectable.

For this example, we will set the current month view to January 2006 using the pagedate property, and we will limit the Calendar's minimum selectable date to January 5, and the maximum selectable date to January 15.