Restrict date selection on date picker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 06:26 PM
Hi all,
I have a catalog item that has a field where the user can select a collection date for their requested item.
I want the default date to be 7 days from the time it was logged and don't want the users to be able to select a date less than 7 days i.e. if the request is being logged on the 1st of June, the date picker should default to 7 days which is 8th June and not be able to select any date between today and the 8th. However, they can choose a date after the 8th.
I created a client script however it does not restrict the user from selecting a date in the past and a date with less than 7 days.
function onLoad() {
var preferredDateField = g_form.getControl('preferred_date_time_for_collection');
var defaultDate = new Date();
defaultDate.setDate(defaultDate.getDate() + 7); // Calculate 7 days from today
// Set minimum date in the date picker
preferredDateField.setAttribute('min', defaultDate.toISOString().split('T')[0]);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 09:39 PM
Hi @reza1921
Please have a look on the below post which could be helpful and an efficient way to handle this :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 10:16 PM
Please use the Below Which may helps you. Change the Field names as per your requirement .
clint script :