Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to overwrite createYearLabel function #1080

Open
doonot opened this issue Apr 30, 2018 · 0 comments
Open

Way to overwrite createYearLabel function #1080

doonot opened this issue Apr 30, 2018 · 0 comments

Comments

@doonot
Copy link

doonot commented Apr 30, 2018

I have two issue with the library and I am wondering if there is a way to overwrite a specific function in pickadate?

  • DatePicker.prototype.nodes.createYearLabel: Instead of using the focusYear, I want to use the current year.
  • DatePicker.prototype.nodes.createYearLabel: I do not want the number of years to be divided by 2:
createYearLabel = function() {
        
        var focusedYear = viewsetObject.year;
        
        settings.equallySplitYears = false;
        settings.useFocusYear = false;

        // if user wants to equally split the years, the year number will be divided in half and added to the
        // lowest year and to the highest year
        if(settings.equallySplitYears) {
            numberYears = settings.selectYears === true ? 5 : ~~( settings.selectYears / 2 )
        } else {
            numberYears = settings.selectYears === true ? 5 : ~~( settings.selectYears )
        }

        // If there are years to select, add a dropdown menu.
        if (numberYears) {

            // initialize variables
            var minYear, maxYear, lowestYear, highestYear;

            if(settings.useFocusYear) {
                // calendar uses the selected year in the dropdown to calculate new years.
                minYear = minLimitObject.year;
                maxYear = maxLimitObject.year;
                lowestYear = focusedYear - numberYears;

                if(settings.equallySplitYears) {
                    highestYear = focusedYear + numberYears;
                }
            } else {
                // calendar uses todays year to calculate new years
                minYear = minLimitObject.year;
                maxYear = maxLimitObject.year;
                lowestYear = nowObject.year - numberYears;

                if(settings.equallySplitYears) {
                    highestYear = nowObject + numberYears;
                }
            } ...

I tried to overwrite this prototype function but I am having problems accessing the DatePicker object. Any hint would be appreciated.

Thanks for this awesome library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant