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

Show Date Picker Only if Default Choice is Empty

  • August 12, 2024
  • 2 replies
  • 57 views

Forum|alt.badge.img+1

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?

Best answer by ahmedA

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.

2 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2050 replies
  • Answer
  • August 12, 2024

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.


Forum|alt.badge.img+1
  • Author
  • 1 reply
  • August 12, 2024

That works now, thanks!