views:

808

answers:

3

I have the two following datepicker objects but I cant get what I want as I am getting stuck with the minDate and maxDate options:

This is to restrict the dates to future dates.

What I want: restrict the dates from current date to 30 years time.

What I get: restrict the dates from current date to 10 years time.

$(".datepickerFuture").datepicker({
    showOn: "button",
    buttonImage: 'calendar.gif',
    buttonText: 'Click to select a date',
    duration:"fast",
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd/mm/yy',
    constrainInput: true,
    minDate: 0,
    maxDate: '+30Y',    
        buttonImageOnly: true
    });

This is to restrict to select only past dates:

What I want: restrict the dates from current date to 120 years ago time.

What I get: restrict the dates from current date to 120 years ago time, but when I select a year the maximum year will reset to selected year (e.g. what i would get when page load from fresh is 1890-2010, but if I select 2000 the year select box reset to 1880-2000) .

$(".datepickerPast").datepicker({
    showOn: "button",
   buttonImage: 'calendar.gif',
    buttonText: 'Click to select a date',
    duration:"fast",
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd/mm/yy',
    constrainInput: true,
    yearRange: '-120:0',
    maxDate: 0,
    buttonImageOnly: true
});

I need help with both datepicker object, any help would be very much appreciated.

Thanks in advance.

Cesar.

+1  A: 

The +30 years one should work fine as shown in this example I created: http://jsbin.com/exiqe3/edit

For -120 years you just need to do the inverse http://jsbin.com/idaxu3/edit

Neil Aitken
For the +30, thats what i thought but I am just getting +10 years.For the -120 years, what do you mean?Thanks.
Cesar Lopez
I just used '-120Y' for the minDate and 0 for the maxDate, if you look at the jsBin links you can see the code I used
Neil Aitken
@Cesar -- the dropdown for year will change based on the current year. It appears to show only -10/+10 from the current year, but respects the min/max values that you supply. Look at the code for _generateMonthYearHeader in the jQuery UI js file.
tvanfosson
@tvanfosson: I am looking at the code for _genereateMonthYearHeader in the Jquery UI js file, and I've changed the 10 for 100, but still doesn't show more than 10. Is there anyway to display more than 10 editing this file? Thanks in advance.
Cesar Lopez
@Cesar - modifying the code **will** work, I'm sure, but I'm not sure that it's a good idea. Having 100 items in a dropdown is a pretty poor interface, IMO. If you are going to make the change be sure that you're not loading the minified (unchanged) version (or that you reminify your updated code). You might want to try using Firebug to make sure that your updated code is doing what it is supposed to.
tvanfosson
@Everyone: Could you take a look at this link ( http://jsbin.com/ivine3 ) to see what I mean on past dates example? When 2000 is selected on year ddl, then 1990, 2010 its gone, to be able to select 2010 back, 2000 has to be selected. Does anyone how to stop this from happening? Thanks.
Cesar Lopez
A: 

Hello all, I fixed my problem which it was the jquery libraries were a bit out date.

If anyone interested on this solution please check on following link.

Source code and result of this question.

Thanks to all of you.

Cesar.

Cesar Lopez
+1  A: 
$("#datepick").datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: 'images/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'dd/mm/yy',
            minDate: '-100Y',
    maxDate: '-1Y', 
    yearRange: '-100',

        });
Srinivas Tamada