On Thu, June 5, 2008 2:43 pm, FSan wrote:
>
> How can I set an "overall" min and max date having 2 dates fields as
> date range?
> That is, not only the fields should restrict each other regarding the
> selected dates but also BOTH FIELDS respect a min and max date.
> Any ideas?
> Thanks
I just did this.
Note that I've got two inputs; dTo and dFrom.
dFrom has a minDate which defines the overall minimum (-3 months)
dTo has a maxDate which defines the overall maximum (today)
The get instance stuff I got from one of the authors when I emailed them
about something else. The _getMinMaxDate function I looked in the
source...
$(document).ready(function() {
$.datepicker.setDefaults({
showOn: 'both',
mandatory: true,
dateFormat: 'dd/mm/yy',
buttonImageOnly: true,
buttonImage: 'Images/calendar.gif',
buttonText: 'Calendar',
showAnim: 'slideDown',
speed: 'fast',
beforeShow: customRange });
$('#dFrom').datepicker({
defaultDate: '-1m',
minDate: '-3m'
});
$('#dTo').datepicker({
maxDate: 0
});
// Customize two date pickers to work as a date range
function customRange(input) {
return {
minDate: (input.id == 'dTo' ?
$('#dFrom').datepicker('getDate') :
$.datepicker._getInst($('#dFrom')[0]._calId)._getMinMaxDate('min')),
maxDate: (input.id == 'dFrom' ?
$('#dTo').datepicker('getDate') :
$.datepicker._getInst($('#dTo')[0]._calId)._getMinMaxDate('max'))};
}
}