Information about bug
When attempting to disable selection of weekend dates (Saturday and Sunday) in a Date field using Frappe’s client-side scripting, the expected behavior does not occur. The DatePicker does not restrict weekend dates, and users are still able to select them.
Steps to Reproduce:
Create a Doctype with a Date field (e.g., joining_date).
Add the following Custom Script:
frappe.ui.form.on('Employee', {
onload: function(frm) {
frm.fields_dict.joining_date.$input.datepicker('option', 'beforeShowDay', function(date) {
const day = date.getDay();
// Disable Saturday (6) and Sunday (0)
return [(day !== 0 && day !== 6), ''];
});
}
});
Open the form and click the calendar icon for the Date field.
Try to select a Saturday or Sunday.
Expected Behavior:
Weekend dates (Saturday and Sunday) should appear disabled in the calendar pop-up and should not be selectable.
Actual Behavior:
Weekend dates are still selectable and appear as normal. The beforeShowDay configuration is seemingly ignored.
Version
ERPNext: v15.52.0 (version-15)
Frappe Framework: v15.56.0 (version-15)
Frappe HR: v15.39.1 (version-15)
Update:
I found the solution by customizing the DatePicker in Frappe’s core.
I added the following snippet inside apps/frappe/frappe/public/js/frappe/form/controls/date.js
using onRenderCell
hook:
onRenderCell: (date, cellType) => {
if (cellType === 'day' && this.df.set_disabled_dates) {
const formattedDate = moment(date).format('YYYY-MM-DD');
if (this.df.set_disabled_dates.includes(formattedDate)) {
return {
disabled: true,
classes: 'disabled'
};
}
}
},
Usage in client script:
frappe.ui.form.on('Your Doctype', {
onload(frm) {
frm.fields_dict["your_date_field"].df.set_disabled_dates = [
"2025-04-20", // Sunday
"2025-04-21"
];
}
});
Also, I have submitted a Pull Request to add this officially in Frappe:
frappe:develop
← aditya-rola:feature/disable-datepicker-dates
opened 05:42PM - 16 Apr 25 UTC
This PR introduces support for disabling specific dates in the DatePicker contro… l by using a new property: **set_disabled_dates**.
Developers can now pass an array of dates (in 'YYYY-MM-DD' format) to disable them in the calendar UI. This is useful in cases where certain days (e.g. holidays, non-working days) should not be selectable by users.
### Technical Details
Modified `frappe/public/js/frappe/form/controls/date.js`
Used the **onRenderCell** hook
Checks if **this.df.set_disabled_dates** exists and disables the matching dates.
### Code added:
`onRenderCell: (date, cellType) => {
if (cellType === 'day' && this.df.set_disabled_dates) {
const formattedDate = moment(date).format('YYYY-MM-DD');
if (this.df.set_disabled_dates.includes(formattedDate)) {
return {
disabled: true,
classes: 'disabled'
};
}
}
},
`
**Example Usage**
`frappe.ui.form.on('Your Doctype', {
onload(frm) {
frm.fields_dict["your_date_field"].df.set_disabled_dates = [
"2025-04-20", // Sunday
"2025-04-21"
];
}
});
`
**Why It Matters**
There is currently no built-in way to disable specific dates in the Frappe DatePicker. This addition provides a flexible and developer-friendly approach to add that behavior without needing to override or modify core widgets via hacky scripts.
<img width="451" alt="image" src="https://github.com/user-attachments/assets/767c06d4-e92b-4bfb-9829-729cdedc7a8d" />
Hope this helps others looking for similar functionality!
Update :
This issue is now resolved and the solution is merged into Frappe core via this PR .
You can now use the disabled_dates
property on Date fields to disable specific dates (e.g., weekends, holidays, etc.) in a clean way.