Solved
Content validation for default date picker
I'm currently using the second date picker from the default qualtrics library. This is the one which actually displays a calendar as opposed to the others that have drop downs. I'd like to be able to validate that the date that is actually chosen is not more than 30 days before the current date.
I believe the other default date pickers allow you to set a range of dates but I would like to use this calendar since it is displayed and I would like for it to be agnostic to when the survey is actually taken so no range is hardcoded. Is there some code I can inject somewhere to do this? I am quite inexperienced with Javascript. Thanks in advance!
Best answer by fleb
Hi @JordanP,
if you'd use jQuery Datepicker (another pop-up calendar), you could allow your respondents to select only dates in the range you want (parameters `minDate` or `maxDate`; you can define it relatively to the current date) and don't let them change the date manually.
!
Note: In the code below I use my own HTML input element (`<input type="text" id="datepicker">`), which value isn't stored by Qualtrics automatically. Therefore I need to tell Qualtrics to store it in an embedded data field whend the page is sbmitted (the `Qualtrics.SurveyEngine.addOnPageSubmit` part of the code ).
1) Define an embedded field called "date" in the survey flow.
2) Create a Descriptive text question in Qualtrics
3) Paste there the following code (using HTML view of the question)
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Datepicker</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker({
minDate: '-30'
});
} );
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
Qualtrics.SurveyEngine.setEmbeddedData( 'date', document.getElementById('datepicker').value );
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
View original
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.