Unable to Disable Weekend Dates in DatePicker Field Using Client Script

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:

  1. Create a Doctype with a Date field (e.g., joining_date).
  2. 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), ''];
        });
    }
});

  1. Open the form and click the calendar icon for the Date field.
  2. 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)

:white_check_mark: 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"
		];
	}
});

:pushpin: Also, I have submitted a Pull Request to add this officially in Frappe:

Hope this helps others looking for similar functionality!

:white_check_mark: 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.