glad / glDatePicker

An ultra-simple, customizable, light-weight date picker plug-in for jQuery
http://glad.github.com/glDatePicker/
274 stars 137 forks source link

How to select more than 5 years back #62

Open mulgurul opened 11 years ago

mulgurul commented 11 years ago

I may be blind, but I cant figure out how to allow more than the default +-5 years range. I need to let users select their birthday. can someone provide an example for this?

Best regards

Peter

MartinGaedeke commented 10 years ago

I have the same problem and to me it seems that there's now way around. You can give something like: selectableYears: [2012, 2013, 2015] and it will work.

selectableYears: [1980, 2013, 2015] however will not work!!!

Unfortunately there is now word about this important "feature" on the plugin page, cost me quite some time :-/

grngc commented 10 years ago

I have the same issue and even after trying all the examples ... the only way to select older dates was to set todayDate ... but that also limits the selection to +/- years from todayDate. I want to let people set their birthDate ... and for that the range must be huge like: selectableDateRange: [ { from: new Date(1904, 8, 1), to: new Date(1996, 12, 31) }, ], selectableDates: [ { date: new Date(1904, 1, 1) }, { date: new Date(1996, 12, 31) } ],

No settings seem to have any effect :(

hayatbiralem commented 10 years ago

Hi,

I had a similar problem, but the solution is not very difficult. Open glDatePicker.js and make the following changes:

1. Change related function

Find:

// Helper function to build selectable list
var getSelectableList = function(min, max, userList) {
    // Build a default list using min/max
    var resultList = [];
    for(var i = min; i <= max; i++) { resultList.push(i); }

    // If user provided a collection, sanitize list by ensuring it's within range and unique
    if(userList) {
        var newList = [];
        $.each(userList, function(i, v) {
            if(v >= min && v <= max && newList._indexOf(v) < 0) {
                newList.push(v);
            }
        });

        resultList = newList.length ? newList : resultList;
    };

    // Sort the values before returning it
    resultList.sort();

    return resultList;
};

Replace:

// Helper function to build selectable list
var getSelectableList = function(min, max, userList, noLimits) {
    // Build a default list using min/max
    var resultList = [];
    for(var i = min; i <= max; i++) { resultList.push(i); }

    // If user provided a collection, sanitize list by ensuring it's within range and unique
    if(userList) {
        var newList = [];
        $.each(userList, function(i, v) {
            if(((v >= min && v <= max) || noLimits) && newList._indexOf(v) < 0) {
                newList.push(v);
            }
        });

        resultList = newList.length ? newList : resultList;
    };

    // Sort the values before returning it
    resultList.sort();

    return resultList;
};

2. Change the line that called the function

Find:

var selectableYears = getSelectableList(todayVal.year - 5, todayVal.year + 5, options.selectableYears);

Replace:

var selectableYears = getSelectableList(todayVal.year - 5, todayVal.year + 5, options.selectableYears, true);

That's it.

shanejdonnelly commented 10 years ago

Thanks for the fix @hayatbiralem Works great as long as you have set the selectableYears option set.

hayatbiralem commented 10 years ago

That's very kind of you. I'm glad to be helpful.

timothy-trized commented 6 years ago

does not work any more this fix it seems :( i also need this for a birthday field...

timothy-trized commented 6 years ago

this does not work any more currently, or i am doing something wrong .. somebody else facing this when using for a birthday field? driving me nuts!