Skip to content
New issue

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

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

Already on GitHub? # to your account

[PLAY-918] DatePicker Disabled Dates Conflict #2648

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,42 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
}
}
const disabledParser = () => {
if (disableDate && disableDate.length > 0) {
return disableDate
} else if (disableRange && disableRange.length > 0) {
return disableRange
} else {
return []
}
const disabledArray=[]

disableDate && disableDate.length > 0 && disabledArray.push(...disableDate)
disableRange && disableRange.length > 0 && disabledArray.push(...disableRange)
disableWeekdays && disableWeekdays.length > 0 && disabledArray.push(...disabledWeekDays())

return disabledArray
}

const disabledWeekDays = () => {
return (
[
(date:any) => {
const weekdayObj: {
[day: string]: number
} = {
Sunday: 0,
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6,
}
return (
date.getDay() === weekdayObj[disableWeekdays[0]] ||
date.getDay() === weekdayObj[disableWeekdays[1]] ||
date.getDay() === weekdayObj[disableWeekdays[2]] ||
date.getDay() === weekdayObj[disableWeekdays[3]] ||
date.getDay() === weekdayObj[disableWeekdays[4]] ||
date.getDay() === weekdayObj[disableWeekdays[5]] ||
date.getDay() === weekdayObj[disableWeekdays[6]]
)
},
]
)
}
const calendarResizer = () => {
const cal = document.querySelector(`#cal-${pickerId}.open`) as HTMLElement
Expand Down Expand Up @@ -127,30 +156,7 @@ const datePickerHelper = (config: DatePickerConfig, scrollContainer: string | HT
disableMobile: true,
dateFormat: getDateFormat(),
defaultDate: defaultDateGetter(),
disable: disableWeekdays && disableWeekdays.length > 0 ? [
(date) => {
const weekdayObj: {
[day: string]: number
} = {
Sunday: 0,
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6,
}
return (
date.getDay() === weekdayObj[disableWeekdays[0]] ||
date.getDay() === weekdayObj[disableWeekdays[1]] ||
date.getDay() === weekdayObj[disableWeekdays[2]] ||
date.getDay() === weekdayObj[disableWeekdays[3]] ||
date.getDay() === weekdayObj[disableWeekdays[4]] ||
date.getDay() === weekdayObj[disableWeekdays[5]] ||
date.getDay() === weekdayObj[disableWeekdays[6]]
)
},
] : disabledParser(),
disable: disabledParser(),
enableTime,
locale: {
rangeSeparator: ' to '
Expand Down