nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker
BSD Zero Clause License
615 stars 191 forks source link

Date cycle got no date option when input is empty #174

Open vorkristof opened 7 years ago

vorkristof commented 7 years ago

This problem appeared when I used PickMeUp for holiday picking where I needed the input field to be empty. I used it in my js file like this:

pickmeup('.pickmeup-date input', {
    position       : 'bottom',
    hide_on_select : false,
    format: 'Y-m-d',
    mode : 'multiple',
    separator: ', ',
    default_date: false,
    date: []
});

So when the date is an empty array it will appear in the site without any starting date in the input field. But there was a bug when I went throuh the day-month-year cycle, it got NaN values for the years and days. I found out that it is not checked in the code where the new date is set.

if (options.mode != 'single') {
    options.current = new Date(options.date[options.date.length - 1]);
}

I fixed the problem with a simple check of the value of the target, so it won't try to set a new date without any reference from the input.

if (options.mode != 'single') {
    if (target.value !== '') {
        options.current = new Date(options.date[options.date.length - 1]);
    }
}
nazar-pc commented 7 years ago

Thanks for reporting this! Confirmed with this demo: https://jsfiddle.net/yyhcncgt/