Prevent user to select date before today on datepicker

Hi, is it possible to block dates or disable the dates on the datepicker. For example: in leave application module employee only able to apply their leave not less than 7 days before their leave. Thus is it possible to block 7 days on the datepicker from today.

yes, it is possible

Could you please share some examples or references to achieve this. I could not find the way to this anywhere. Most of the thread leads to create a validation check instead of blocking the datepicker. Thank you.

please check this document

https://api.jqueryui.com/datepicker/#option-minDate

image

Thank you so much for your reply
Though i have a question.

is there a specific syntax i have to use to link it to the from_date?
for example employee cannot select any day before today.

cur_frm.fields_dict.from_date.datepicker({
minDate: new Date(2007, 1 - 1, 1)
});

When i try to implement the script it still does not block the other dates
image
this is my script
image
Thank you

Try
minDate: frappe.datetime.get_today()

I have adjust but i can still choose other dates :frowning:

Try this

cur_frm.fields_dict.from_date.datepicker.update({
minDate: new Date(2007, 1 - 1, 1)
});

https://docs.erpnext.com/docs/v13/user/manual/en/customize-erpnext/client-scripts/date-validation

refresh: function (frm) {
frm.fields_dict.date.datepicker.update({
minDate: new Date(frappe.datetime.get_today()),
});
},

“date” is the field name

1 Like