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

Infinite loop when no enabled dates in current year #171

Closed
b4tch opened this issue Dec 31, 2020 · 11 comments
Closed

Infinite loop when no enabled dates in current year #171

b4tch opened this issue Dec 31, 2020 · 11 comments

Comments

@b4tch
Copy link

b4tch commented Dec 31, 2020

We found an issue whereby is_disabled was always returning true, resulting in an infinite loop and hanging our site. It is only caused when there are no enabled dates left in the current year, and the only enabled days are in January of the next month before the current day number (so in our case, only December 31st was affected).

We are using v1.9.0 and the resolution was to add the following code after line 772 (after "first_selectable_month = 11;"):

first_selectable_day = new Date(first_selectable_year, first_selectable_month + 1, 0).getDate();

and also this code after line 781 ("first_selectable_month = 0;"):

first_selectable_day = 1;

I believe the latest version (v1.9.17) is still affected but that's minified so I can't tell you how to change that, sorry.

Hope that helps someone out.

@stefangabos
Copy link
Owner

can you please post how the disabled_dates is built?

@stefangabos
Copy link
Owner

I used
disabled_dates: ['31 12 2020']
and it didn't break, but maybe I can reproduce it with your setup

@b4tch
Copy link
Author

b4tch commented Dec 31, 2020

Sorry, I meant to state that in my original post. I am disabling all dates by default ([* * *])

@stefangabos
Copy link
Owner

ok, then what are you using for enabled_dates :)
i need to be able to reproduce it

@stefangabos
Copy link
Owner

just post the values you are using to create the date picker

@b4tch
Copy link
Author

b4tch commented Dec 31, 2020

var enabledDates = ["31 12 2020 1-5","2 1 2021 1-5","3 1 2021 1-5","4 1 2021 1-5","5 1 2021 1-5","6 1 2021 1-5","7 1 2021 1-5"];

$('#calendar_collectiondate').Zebra_DatePicker({
always_visible: $('.the_calendar'),
disabled_dates: ['* * *'],
enabled_dates: enabledDates,
direction: true,
first_day_of_week: 0,
format: 'Ymd',
select_other_months: true,
onSelect: function(a,b,dateObj,d){
dateSelected(dateObj);
}
});

@stefangabos
Copy link
Owner

ok, i was able to reproduce it by removing 31 12 2020
awesome, working on it, thank you!

@b4tch
Copy link
Author

b4tch commented Dec 31, 2020

Ahh yes, sorry - that date gets removed through some other code and I neglected to remove it from the example.

Great plugin by the way, thank you for it :)

stefangabos added a commit that referenced this issue Dec 31, 2020
@stefangabos
Copy link
Owner

Should be fixed now. Do you want me to do a new release so you can grab it via npm?
Are you able to use the latest version or you must stick to 1.9.0?

@b4tch
Copy link
Author

b4tch commented Dec 31, 2020

Our current fix is adequate for now, assuming what I suggested in the original post is satisfactory. We could probably upgrade to the latest version but it would require some testing which I won't be doing on New Years Eve haha. Thanks for the speedy fix!

@stefangabos
Copy link
Owner

i haven't looked at the solution you provided until now, but that is exactly what the solution was (only also needed at a different place). thanks a lot for the feedback and a happy new year!

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

2 participants