WhatSock / apex

Apex 4X: The Comprehensive ARIA Development Suite
MIT License
28 stars 10 forks source link

Disabled date ranges years/months selection #46

Closed impetoyt closed 1 year ago

impetoyt commented 1 year ago

ARIA DATE PICKER (WITH ABSOLUTE DISABLED DATE RANGES) Configure absolute and relative disabled date ranges (no earlier than 1st January 2020, and no later than 3 days after today): https://whatsock.com/Templates/Datepickers/With%20Absolute%20Disabled%20Date%20Ranges/index.htm

In the example above I digited in the input field 08/01/2007 and after I opened the picker. In this case the picker it will opens on the date 08/01/2007 and nothing at least on apparance/styles is selectable.

case 1) If I'm using the keyboard I can't navigate through years or months selection (both are disabled), so I can't change the date inside the piker. case 2) if I'm using the mouse the years selection is disabled but I can change the months selection also if it is disabled and I will go directly to the max date or min date.

accdc commented 1 year ago

Hi, thanks for reporting this. I've already pushed the fix for this in the latest download which can be tested here: https://whatsock.com/Templates/Datepickers/With%20Absolute%20Disabled%20Date%20Ranges/index.htm

impetoyt commented 1 year ago

Hi, thanks for reporting this. I've already pushed the fix for this in the latest download which can be tested here: https://whatsock.com/Templates/Datepickers/With%20Absolute%20Disabled%20Date%20Ranges/index.htm

I think there is another issue with this new fix, at this links: https://whatsock.com/Templates/Datepickers/Basic/index.htm https://whatsock.com/Templates/Datepickers/Basic/index.htm

I open the chrome console and I tried to use the presetDate method: $A("UniqueCalendarId").presetDate($A("UniqueCalendarId"), new Date("2021-07-13"), new Date("2021-07-03"), new Date("2021-07-23"));

It will display the follow error message: VM1040:10 Uncaught TypeError: Cannot read properties of undefined (reading 'month') at t.isDisabledDate (eval at success (4X.js:7:35961), :10:8810) at t.presetDate (eval at success (4X.js:7:35961), :10:10836) at :1:24

I debug a little in Datepicker.js, it's seems that the parameter a is undefined so when the code reach a.month or a.year it will give the error:

                isDisabledDate: function(e, t, n, a) {
                    a = a || e.range.current;
                    var r = e.range[a.month].disabled[a.year]
                      , o = e.range[a.month].disabled["*"]
                      , a = e.range[a.month].disabledWDays
                      , s = e.range.disabledWDays
                      , d = n.getDay();
                    return !!(r && -1 !== $A.inArray(t, r) || o && -1 !== $A.inArray(t, o) || a.length && -1 !== $A.inArray(d, a) || s.length && -1 !== $A.inArray(d, s) || e.isOutsideDateRange(n))
                },
accdc commented 1 year ago

I'm confused, are you trying to set a calendar that is already rendered or one that is not open yet? The presetDate method is only called at a specific point in the lifecycle process so it won't work if you call it out of the blue like that.

impetoyt commented 1 year ago

I just opened the two page and called the presetDate method from the google console without open the calendar or digit something in the input field. So in order to use the presetDate what should I do? Before the fix the presetDate method works without any problem

accdc commented 1 year ago

That makes sense why it would fail then. If you look at the code within 4X/Modules/Datepicker.js, you will see that "dc.presetDate" only executes after there is a specific date format configured for that purpose within the beforeRender method. It's purpose is simply the check the value of the input field before the calendar opens.