-
Notifications
You must be signed in to change notification settings - Fork 436
Description
I have included a "min" value that can have two possible values depending on a specific condition. These values can either be from the current day or the following day. However, there is also an invalid array with some dates that cannot be selected.
If the current day's "min" value falls within the invalid date range, it should be ignored and the selection should be adjusted to the next valid date. Unfortunately, this is not happening because the "min" value is set to the current day. As a result, the invalid date array is being bypassed and the user is able to select today's date, which should not be the case.
``
// Function to set updated max and min date
let sameDayDeliveryEnable = {{settings.same_day_delivery}};
let cutoffHour = {{settings.cutoff_time_same_day_delivery}};
let earliestDeliveryDate = document.querySelector(".earliest-delivery-date");
let currentDateTime = new Date();
let currentHour = currentDateTime.getHours();
let todayDate = currentDateTime.toISOString().slice(0, 10);
let tomorrow = new Date(currentDateTime.getTime() + 24 * 60 * 60 * 1000);
let tomorrowDate = tomorrow.toISOString().slice(0, 10);
let maxYear = new Date();
maxYear.setFullYear(maxYear.getFullYear() + 1);
maxYear = maxYear.toISOString().slice(0, 10);
let maxRange, minRange;
// Set max date
maxRange = maxYear
// Set min date
if (currentHour < cutoffHour) {
if (sameDayDeliveryEnable) {
minRange = todayDate;
earliestDeliveryDate.innerHTML = todayDate;
} else {
minRange = tomorrowDate;
earliestDeliveryDate.innerHTML = tomorrowDate;
}
} else {
minRange = tomorrowDate;
earliestDeliveryDate.innerHTML = tomorrowDate;
}
// To get the last 5 disabled dates
let today = new Date();
let numberOfDaysOff = {{settings.minus_no_of_days}};
let dd = String(today.getDate()).padStart(2, '0');
console.log(dd);
let mm = String(today.getMonth() + 1).padStart(2, '0'); // 03
let yyyy = today.getFullYear();
let nextyyyy = today.getFullYear()+1;
let lastDayofMonth = new Date(yyyy,mm, 0).getDate();
mobiscroll.datepicker('#inline-picker', {
controls: ['date'],
touchUi: true,
setText: 'Confirm',
cancelText: 'X',
selectSize: 3,
min:minRange,
max:maxRange,
circular:true,
invalid:[
{{ settings.delivery_off_days}},
{
start: `${yyyy}-01-${31 - numberOfDaysOff}`,
end: `${yyyy}-01-31`
},
{
start: `${yyyy}-02-${29 - numberOfDaysOff}`,
end: `${yyyy}-02-29`
},
{
start: `${yyyy}-03-${ 31- numberOfDaysOff}`,
end: `${yyyy}-03-31`
},
{
start: `${yyyy}-04-${30 - numberOfDaysOff}`,
end: `${yyyy}-04-30`
},
{
start: `${yyyy}-05-${31 - numberOfDaysOff}`,
end: `${yyyy}-05-31`
},
{
start: `${yyyy}-06-${30 - numberOfDaysOff}`,
end: `${yyyy}-06-30`
},
{
start: `${yyyy}-07-${31 - numberOfDaysOff}`,
end: `${yyyy}-07-31`
},
{
start: `${yyyy}-08-${31 - numberOfDaysOff}`,
end: `${yyyy}-08-31`
},
{
start: `${yyyy}-09-${30 - numberOfDaysOff}`,
end: `${yyyy}-09-30`
},
{
start: `${yyyy}-10-${31 - numberOfDaysOff}`,
end: `${yyyy}-10-31`
},
{
start: `${yyyy}-11-${30 - numberOfDaysOff}`,
end: `${yyyy}-11-30`
},
{
start: `${yyyy}-12-${31 - numberOfDaysOff}`,
end: `${yyyy}-12-31`
},
{
start: `${nextyyyy}-01-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-01-31`
},
{
start: `${nextyyyy}-02-${29 - numberOfDaysOff}`,
end: `${nextyyyy}-02-29`
},
{
start: `${nextyyyy}-03-${ 31- numberOfDaysOff}`,
end: `${nextyyyy}-03-31`
},
{
start: `${nextyyyy}-04-${30 - numberOfDaysOff}`,
end: `${nextyyyy}-04-30`
},
{
start: `${nextyyyy}-05-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-05-31`
},
{
start: `${nextyyyy}-06-${30 - numberOfDaysOff}`,
end: `${nextyyyy}-06-30`
},
{
start: `${nextyyyy}-07-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-07-31`
},
{
start: `${nextyyyy}-08-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-08-31`
},
{
start: `${nextyyyy}-09-${30 - numberOfDaysOff}`,
end: `${nextyyyy}-09-30`
},
{
start: `${nextyyyy}-10-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-10-31`
},
{
start: `${nextyyyy}-11-${30 - numberOfDaysOff}`,
end: `${nextyyyy}-11-30`
},
{
start: `${nextyyyy}-12-${31 - numberOfDaysOff}`,
end: `${nextyyyy}-12-31`
},
{
recurring: {
repeat: 'weekly',
weekDays: 'SU'
}
}
]
});