I am trying to build a date range picker in the survey, to allow participant to select the date range of travelling abroad.
I read some posts about flatpickr and it seems to be an option to do so.
However, I have no background of JavaScript.
Could anyone advise how should it be done to embed the date range picker?
Thanks!
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
Use the below code in the text entry question
jQuery("#"+this.questionId+" .InputText").flatpickr({
dateFormat: "Y-m-d H:i",
minDate: new Date()
});
> Put the below code in the look & feel -> General -> header -> source view(<>)
>
> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
> <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
>
> Use the below code in the text entry question
>
> jQuery("#"+this.questionId+" .InputText").flatpickr({
> dateFormat: "Y-m-d H:i",
> minDate: new Date()
> });
>
>
I tried to insert the code into the text entry question into "Add Java Script" window.
And the following message popped up. "Invalid JavaScript! You cannot save until you fix all errors: Invalid regular expression."
How should it be done actually? Would appreciate more guidelines on this! Thanks!
Clear the JS and paste it inside onReady function of text entry question JS
rondev Hi rondev, thanks for the help above regarding the flatpickr code. I came across flatpickr when trying to get a month only view as it had been announced that flatpickr now had that functionality through some sort of plugin attribute (https://flatpickr.js.org/plugins/) (see pic below for the result)
I added in the altered code with the plugin part (see https://flatpickr.js.org/plugins/ )
uatrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
jQuery("#"+this.questionId+" .InputText").flatpickr({
//dateFormat: "Y-m-d H:i",
inline: true,
//minDate: new Date(),
static: true,
altInput: true,
plugins: l
new monthSelectPlugin({
shorthand: true, //defaults to false
dateFormat: "m.y", //defaults to "F Y"
altFormat: "F Y", //defaults to "F Y"
theme: "dark" // defaults to "light"
})
]
});
});
and then from a thread (https://github.com/flatpickr/flatpickr/issues/269) I found out that I needed to change the href and script in the look and feel section to include the additional lines:
I'm not sure if you need all 4 lines but it works as it is.
I piped the previous question answer over and it gives (I changed the dateFormat to d/m/y to get this:
I guess there are many other alternatives for Month Views but due to my minimal knowledge of JS script, it's often difficult to work out how to map it and get it working. If you have any JS tips or guidance for the future or know of a really good JS script course (for Qualtrics) that would be great.
Thanks
Rod Pestell
I would like to enter a field to record the current date and time(arrival time) into a survey. Plus I would like a field to give the current date but to edit the time to later in the day (estimating departure time). I don't have any idea about coding, but am excellent at cutting and pasting. Can anyone help? Thanks
Kirrily_Rourke Although a little late replying (sorry!) I'd do two separate flatpickr fields and then combine the results together via an embedded field in the survey flow. If you want the system to understand it as a true timestamp, I presume you need to follow the proper UTC format which has a T in the middle and a Z at then end.
Hope that helps
Rod Pestell
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.