Flatpickr date not storing data with survey | XM Community
Question

Flatpickr date not storing data with survey


Userlevel 4
Badge +7

As a follow up to my last post:

I got it to display beautifully, but the question doesn’t seem to be storing the date value after completing the survey. I’m not sure if somehow it has to do with using the Simple Layout option for a Theme or what… 

 I even commented out some stuff in case that was the reason, but it doesn’t seem to make a difference in whether it gets stored or not.

I even tried to store it as embedded data prior to submitting the survey and that didn’t make a difference either.

I don’t know how else to troubleshoot the data value not getting saved/stored with the survey response…. Please send help.


12 replies

Userlevel 5
Badge +17

Hey @courtrc , sorry to hear about the issues. Can you confirm if it’s at least inputting the information in-survey, just not saving? Or will nothing appear filled in when entering info on the survey?

@Tom_1842 may be able to assist more on this issue since he helped so much with your last inquiry!

Userlevel 7
Badge +27

Your jQuery selector is incorrect, so it isn’t finding the Qualtrics input field.  Replace .text-input with .InputText.

Userlevel 4
Badge +7

@tannerfaragher I’m not exactly sure what you’re asking but selecting the date from the Flatpickr in the survey does input a date into the field. I included a screenshot of that above. It’s just not saving. Every other piece of data in the survey saves, just not the date when submitting the survey.

I even tried to inspect the survey to see but I’m not technically savvy to look into if there’s something going wrong from when the date is showing as selected in the field and upon clicking submit.

Userlevel 5
Badge +17

@courtrc, thanks for the info, and sorry for the confusion on my reply. Yes, I was just checking to see if selecting the date from Flatpickr did at least put the date in the field. It sounds like Tom has a potential fix, hope it works! Y’all are awesome!

Userlevel 4
Badge +7

@TomG thank you so much! How would I know where to look for the correct jQuery selector name in the future?

I know how when inspecting the field I can see the class=”text-input” which was what I had in there from my previous posts’ suggested solution, but not sure how/where to look to know I’ve got the right jQuery selector.

 

Userlevel 4
Badge +7

@TomG unfortunately, that change actually made it so the Flatpickr doesn’t display at all now. I’m assuming something to do again with using the Simple Layout Theme.

 

Userlevel 7
Badge +27

Based on the screen shot, .text-input is correct. You have an atypical variety of Qualtrics - maybe related to simple layout. Therefore, I’m not sure why it isn’t saving.

I was going to mention that in your header, you are loading flatpickr twice. You only need to load the flatpickr css and flatpickr js once.

Userlevel 7
Badge +27

Hello! Sorry about that, I only tested getting Flatpickr to display, not saving the values.

This is indeed specific to Simple layout. I tried a couple methods to get the value to save to an input or embedded data field, but unfortunately none of them panned out.

Saving the value to an input field, either the input where Flatpickr is initialized or a separate/hidden input field that populates with the value of Flatpickr when a date is selected, did not work. The values get wiped away from the input fields as soon as the Next button is pressed. The value was retained in the input field IF the input field was clicked into and a keypress was recorded, but just setting the value with JS did not actually save it to the input. My attempts to simulate this keypress programmatically also did not pan out.

Saving the value to an embedded data field also did not work. When trying to use Qualtrics.SurveyEngine.setEmbeddedData, I encountered an error message in the console that I have not seen before. "setEmbeddedData deprecated, please use `setJSEmbeddedData`". I updated to Qualtrics.SurveyEngine.setJSEmbeddedData, but this does not appear to do anything at this time.

So I think currently with Simple Layout, inputs have to actually be typed into for the values to be saved. Without a way to save the Date value to an input field or to an Embedded Data field, I am not sure how to record the Flatpickr selection.
 

Userlevel 4
Badge +7

@Tom_1842 Appreciate all your attempts to solve this conundrum. I’ll just hold off for now and just resort to a text field with a date format validation which is a bummer cause Flatpickr is so slick.

I wish I knew how to mark this as Not Resolved anymore. But I don’t know who to even contact for that. I don’t think submitting a support ticket makes sense for that but idk who else to try to contact or if there’s a way to tag an admin user to this thread. 😒

Userlevel 7
Badge +27

Happy to help, and sounds good. @AmaraW is a Community Admin and might be able to help here.

Badge +42

@courtrc & @Tom_1842 - all fixed 😃

Userlevel 7
Badge +27

Hi @courtrc, so I found a hint on this page about setting Embedded Data and the below is working for me to store Flatpickr selections with Simple Layout. First, the hint:

setJSEmbeddedData(key, value)
Sets embedded data on the page. Only embedded data fields in the namespace _js can be set by this method.

The full process:

Add the below to the Survey's Header:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/themes/dark.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.js"></script>

Next, create a Text Entry question and add the below to the question's JavaScript in the OnReady section:

jQuery("#question-"+this.questionId+" .text-input").flatpickr({
dateFormat: "Y-m-d",
onChange: function(selectedDates, dateStr, instance) {
Qualtrics.SurveyEngine.setJSEmbeddedData("date1",dateStr);
}
});

Finally, in the Survey Flow, add the following Embedded Data field at the top of the Survey Flow:

__js_date1

The Flatpickr selection will be saved to the "__js_date1" Embedded Data field, even though it being set to “date1” in the JavaScript.

Leave a Reply