calendar | XM Community
Question

calendar

  • 8 March 2024
  • 8 replies
  • 54 views

Badge +2

Hello. I am using one of the 3 calendar question from the Qualtric library (Demographics-Calendar and Date Questions-Enter a date). I want to make sure that the choosen date is not beyond the current date. How can I do this?  Can I use a condition like Display Logic or do I need to write code? Thanks, Al


8 replies

Userlevel 7
Badge +36

You would need a code for it.

Userlevel 6
Badge +33

@AL_2022 I would highly recommend using Flatpickr instead of Qualtrics’ options. 

 

Put this code in the header: 

<link href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css" rel="stylesheet" /><script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

 

 

Then, use a Text Entry question for your date question and add the following code to the JavaScript:

 

Qualtrics.SurveyEngine.addOnload(function()

{

/*Place your JavaScript here to run when the page loads*/

 

 

jQuery("#"+this.questionId+" .InputText").flatpickr({

dateFormat: "m/d/Y",

maxDate: "today" 

});

 

 

 

});

 

 

 

 

Badge +2

Sorry. Put the code in the header via Look and Feel - General - Header or the question itself?

And the Java code: add  it to the same date question (imported from the Qualtrics library) or create a new Text entry question? Also will it be in the dd/mm/yyyy format?

 

Could you please clarify.

 

Thanks.

Userlevel 6
Badge +33

@AL_2022 

The header code should go in the Look and Feel->General->Header. When pasting it, make sure you click on the <> button first.

 

The actual JavaScript code should be added to a new, Text Entry question. This will be used instead of the one you brought in from the Qualtrics library. You can delete that one. 

 

If you want the date in a dd/mm/yyyy format, change the dateformat that I have in the code to the following: 

 

dateFormat: "d/m/Y",

Badge +2

Thanks Josh! Unfortunately its not working. please see the attached screenshots.

 

 

Userlevel 6
Badge +33

@AL_2022 what happens when you click in the box to enter the date?

Badge +2

Hi. Nothing happens unfortunately. treats it as a normal text question…

 

 

OSqiy

Badge +2

Hi Josh,

 

It’s working now!  It doesn’t work in the Simple layout  so I  had to use the Flat layot. The latter is not ideal but I don’t want to add a substantial code in case it doesnt work. But below is the link for the solution:

 

https://community.qualtrics.com/survey%2Dplatform%2D54/flatpickr%2Dnot%2Ddisplaying%2Dwith%2Dsimple%2Dlayout%2D23169

 

Thank you very for your help! Regards, Al

 

 

Leave a Reply