Seeking JavaScript assistance on AEM Form date picker
Hi Community,
I am seeking help on writing a piece of JavaScript to limit date picker and only allow selection from today + 7 days, as I am told the only way is putting code in rule editor.
Without the IT knowledge and resource, I turned to ChatGPT for help, but it didn't work.
Therefore, I want to find out what's wrong with the JavaScript ChatGPT gave me. Pasting them below
(I clicked copy selector and got this, then replaced ".datepicker" with it: #guideContainer-rootPanel-guidedatepicker__)
First try:

(function ($) {
$(document).on("dialog-ready", function () {
// Get the date picker widget
var datePicker = Granite.UI.Foundation.Utils.getDatePicker($("#guideContainer-rootPanel-guidedatepicker__"));
// Get the current date
var currentDate = new Date();
// Calculate the date four days from now
var futureDate = new Date(currentDate.getTime() + (4 * 24 * 60 * 60 * 1000));
// Set the minimum and maximum date values of the date picker
datePicker.setDisabledDates({
from: currentDate.toISOString(),
to: futureDate.toISOString()
});
});
})(Granite.$); |
Second try:

document.addEventListener("DOMContentLoaded", function () {
var datePicker = document.querySelector("#guideContainer-rootPanel-guidedatepicker__");
datePicker.addEventListener("coral-datepicker:ready", function () {
var currentDate = new Date();
var futureDate = new Date();
futureDate.setDate(currentDate.getDate() + 4);
datePicker.min = formatDate(currentDate);
datePicker.max = formatDate(futureDate);
});
function formatDate(date) {
var year = date.getFullYear();
var month = String(date.getMonth() + 1).padStart(2, "0");
var day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
}); |
I also don't understand this error

Thanks so much in advance!



