End survey based on date difference | XM Community
Solved

End survey based on date difference

  • 27 November 2023
  • 14 replies
  • 76 views

Userlevel 1
Badge +2
  • Level 2 ●●
  • 27 replies

Hi, 

I have created an event attendance form. Users will be required to enter the date they will be attending the Conference event. This question is set up as a form field that users will enter the date. 

ASK: 

If user enters date that is less than 30days from the date they are filling out the form I want the form to terminate. I mean i want the form to end and prevent them from completing if the current date is less than 30days from the date they enter. 

 

I am just going to tag a few resourceful names I know who have provided assistance to other issues on this platform just to draw attention. @Deepak 

Also anyone can Please help me out I'm on a timeline and would greatly appreciate any assistance you can provide.

icon

Best answer by Deepak 28 November 2023, 14:43

View original

14 replies

Userlevel 7
Badge +36

@Bee 

You would need to do date calculation here based on input date via javascript, I would recommend using date picker for the date format to be consistent. Post which you can update an embedded data if its greater or lesser than 30 days and include branch logic either to go ahead or terminate based on it in survey flow.

Hope it helps!

 

Userlevel 1
Badge +2

I really appreciate the quick response! 

 

@Deepak I unfortunately have very little knowledge with JavaScript and will need step by step instruction on how to get this done please. Also you mentioned embedded data, I am completely lost on how to go about that too. 

I know its a lot to ask but would really appreciate any help you can provide 

Userlevel 4
Badge +15

@Bee  How about a calendar with available dates only after 30 days.

 

Try this. 

 

Here you can control minDate and maxDate based on your requirement.

 

Thanks,

Jagdish

Userlevel 7
Badge +36

@Bee 

To add to Jagdish’s point you can show a calendar which shows date which are 30 days from the date they are filling form through flatpickr and using min date.
 

Header:

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

Question:

Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#"+this.questionId+" .InputText").flatpickr({

minDate: new Date().fp_incr(30) ,

dateFormat: "d/m/Y"});
});

Preview:
 

Hope it helps!

Userlevel 1
Badge +2

@Deepak 

Thank You soo much that was really helpful. I have been able to add the datepicker to the the question but i can’t seem to limit the selection to only 30days from the current date.

 

I can’t seem to figure out where to put this code you added in your response 

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

 

Also I added the below code to the javascript on that question but it’s not making any difference.  

“Qualtrics.SurveyEngine.addOnload(function() { jQuery("#"+this.questionId+" .InputText").flatpickr({ minDate: new Date().fp_incr(30) , dateFormat: "d/m/Y"}); });”

I tried the other options mentioned in the old chats you sent but its not working. 

I believe I’m not doing something right,  kindly clarify for me. Thank You

 

Userlevel 7
Badge +36

@Bee

According to my understanding you wanted to terminate if user entered date that is less than 30 days. 

For example, if user entered tomorrows date it should be terminated right? So, what I did is in the date picker above it won’t allow user to select the date which is within +30 days from today.

Include the header code in look n feel> general> header then edit it and click on source from the above and paste it.
 

Additionally, make question required>force response!

Userlevel 1
Badge +2

Yes @Deepak i want the survey to terminate if user selects a date less than 30days. 

 

  1. Look and Feel>General>Header, I clicked edit and pasted the code below

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

 

  1. Also, I have pasted the below code into the javaScript of the question:

“Qualtrics.SurveyEngine.addOnload(function() { jQuery("#"+this.questionId+" .InputText").flatpickr({ minDate: new Date().fp_incr(30) , dateFormat: "d/m/Y"}); });”

 

I just run some tests but the survey keeps going even when i selected 29th Nov, 30 Nov which are both less than 30days. Am i still doing something wrong please?

Userlevel 7
Badge +36

@Bee 

Can you show how you have included it? and what are you seeing in preview?

Userlevel 1
Badge +2

@Deepak See screenshots below please, 

 

 

Userlevel 1
Badge +2

@Deepak also this is what i see in preview

 

Userlevel 7
Badge +36

@Bee 

You’ve included qualtrics date question remove that and include normal text entry question.

And header is incorrect click on source its and then paste the code.

Userlevel 1
Badge +2

@Deepak 

Also the question type is already a “text entry”, I am unsure if that is what you meant. 

  1. I have made this correction. I have pasted the code in the source of the Header edit box.
  2. After running some test again, it is still not working. 

Screenshot below shows that the question was already in ‘text entry’ format. I am unsure if that is what you meant by “include normal text entry question” so please see screenshot below. 

 

Userlevel 7
Badge +36

@Bee 

Kindly delete the question and include new text entry or remove HTML from question.

You have now include date question from qualtrics library.

Hope it makes sense.

Userlevel 1
Badge +2

Yesss!!!! It works. Thank You soo much @Deepak you deserve a medal😊. 

I really appreciate your assistance.

Leave a Reply