Hi All, I have two date selection questions in my survey where I would like one of them to only have respondents be able to select Saturdays and the other to only be able to select every other Sunday. Is there a code for this? And how would I input this code? Also, can I add quotas so only a certain number of respondents can select each day? I appreciate your help as I am relatively new to Qualtrics. Thank you in advance!
Custom Calendar-Only Having one day available to select
Best answer by JesperAndersen
Just in cases anyone needs the complete JS, this is tested and working:
Qualtrics.SurveyEngine.addOnReady(function()
{
function getAllSaturdays(year) {
const saturdays = [];
const date = new Date(year, 0, 1); // January 1st of the given year
while (date.getFullYear() === year) {
if (date.getDay() === 6) { // Saturday is day number 6 (0 is Sunday)
const dateString = date.toISOString().slice(0, 10); // Format the date as "YYYY-MM-DD"
saturdays.push(dateString);
}
date.setDate(date.getDate() + 1); // Move to the next day
}
return saturdays;
}
const allSaturdays2023 = getAllSaturdays(2023);
jQuery("#"+this.questionId+" .InputText").flatpickr({
dateFormat: "Y-m-d",
minDate: new Date(),
enable: allSaturdays2023
});
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.