On Sun, June 15, 2008 7:48 am, Shawn wrote:
>
> I'm having a problem wit the ui.datepicker.  Specifically
> setting/getting the default date.  I have the following function:
>
> function setDefaultDates() {
>    var temp = new Date();
>    var sd = new Date(temp.getFullYear(), temp.getMonth(), temp.getDate()
> - 8);
>    var ed = new Date(temp.getFullYear(), temp.getMonth(), temp.getDate()
> - 1);
>
>    $("#criteriaStart").datepicker("setDate", sd);
>    $("#criteriaEnd").datepicker("setDate", ed);
>
> alert(sd + "\n" + $("#criteriaStart").datepicker("getDate"));
>
>    $("#criteriaStart").val($.datepicker.formatDate( "d M yy",
> $("#criteriaStart").datepicker("getDate") ));
>    $("#criteriaEnd").val($.datepicker.formatDate( "d M yy",
> $("#criteriaEnd").datepicker("getDate") ));
>
>    return;
> }
>
> The alert() is showing that sd does have a value, but the
> datepicker("getDate") bit returns null.
>
> So, the rest of the routine obviously fails because there doesn't appear
> to be any value stored in the datepicker.

I had the problem the other week, basically the datepicker doesn't let you
do getDate until after it's been displayed.  I emailed the folks who wrote
datepicker and they did get back with a solution, but that's at work and
I'm not for the next week.

I can get it you then... but from memory,

$('#dFrom').datepicker({
    defaultDate: '-1m',
    minDate: '-3m'
});

set the date correctly, to get the date you need the instance...

$.datepicker._getInst($('#dFrom')[0]._calId)._getMinMaxDate('min')

that gets the MinMaxDate, I can't remember what the GetDate function is
called.

You might be interested in the rest of the code, two textboxes with custom
range with overall min/max set...

$('#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'))
    };
}

Sorry I can't give you the exact code, but I think once you get the
instance you've got the rest.

J.

Reply via email to