Show Date Picker Only if Default Choice is Empty | XM Community
Skip to main content

Hi,

Currently I am editing a survey. I have a question block where one of the fields is a question where users needs to enter the date. The question type is a Form field.

Sometimes, we create pre-filled links, so in that question, we used something like:

${e://Field/SomethingDate}

as the default choice. When we give the links, the URL will be like:

https://<Survey URL>/jfe/form/<Form ID>?SomethingDate=<Date>

I had entered a JavaScript to include a date picker using Pikaday+moment:

Qualtrics.SurveyEngine.addOnload(function()
{
var inputId = 'QR~' + this.questionId;
var picker = new Pikaday (
{
field: document.getElementById(inputId),
firstDay: 1,
maxDate: new Date(),
format: 'YYYY/MM/DD',
toString(date, format) {
var formattedDate = moment(date).format('MMM DD, YYYY');
return formattedDate;
}
}
);

});

The date picker doesn’t show up in that question though.

The script does work if I add in a new question with a text entry type. How do I make the script behave for form field questions?

Every form field also has a serial number atttached to it.

So, you’ll need to change 'QR~' + this.questionId; to 'QR~' + this.questionId + ‘~1’; or 2,3,4… based on the field number.


That works now, thanks!


Leave a Reply