Restricting the date range
Your application may need to restrict allowable date selections for limiting the date range. Perhaps this is predicated on some other condition being true or event being triggered. Thankfully, we have enough flexibility to handle the most common selection-restricted configurations of the widget.
Getting ready...
We'll use the basic input element markup for our datepicker widget:
<div> <label for="start">Start:</label> <input id="start" type="text" size="30"/> </div>
How to do it...
We'll create our datepicker widget as follows, using the minDate
and maxDate
options.
$(function() { $( "input" ).datepicker({ minDate: new Date(), maxDate: 14 }); });
When we activate the datepicker widget by clicking on the input
field, you'll notice that only a specific range of days are selectable.
How it works...
Both the minDate
and
maxDate
options accept a variety of formats. In our example here, we gave the minDate
option...