How to change Custom Validation when a timer runs out | XM Community
Skip to main content

Hello everybody!
The goal for the participants of my survey is to solve as many exercises as possible in a limited amount of time.
Every exercise consist of a five-choice "Constant Sum"-Question, where the participants have to give their answers. These answers are checked via Custom Validation (Only one answer per choice is correct) and when the participant clicks the Next Button and all the answers are correct, the next exercise appears. If not, an error message is shown to the participants and they have to solve the same exercise again.
I implemented a timer that spans pages that I found here: https://medium.com/@mc_bloomfield/javascript-and-qualtrics-getting-started-34f113cbeaaa
The problem I have right now, is that if the timer is up, the participants should not be able to finish their current exercise and the questionblock should be finished right then and there.
Unfortunately, just using the "jQuery('#NextButton').click();" command in the JavaScript when the timer runs out returnes the error-message, if the entries of the exercises are not correct. The error-message should appear as long the timer is running, but not after.
I tried to add another custom validation considering the timer, but this is quite hard: Unfortunately, it is not possible to use embedded data in custom validation, so I tried to implement another text field that changes its value when the timer is up, but I did not manage to get this right.
This is the code I considered for rewriting the value (and when it is set correctly, the page can be left without checking the other validations):
Qualtrics.SurveyEngine.addOnReady(function()
{
//run this command every second
var timer = window.setInterval(timeUpCheck, 1000);
function timeUpCheck() {
//TimeUp is an embedded variable and is changed from 0 to 1 when the timer runs out (programmed in header)
var timeUp = Qualtrics.SurveyEngine.getEmbeddedData('TimeUp');
jQuery("#"+this.questionId+" li input[type=text]").val(timeUp);
};
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
clearInterval(timer);


});
Unfortunately, I've run out of ideas and google didn't help either...
Thanks in advance for your help or useful tips!

You can look at this discussion: https://www.qualtrics.com/community/discussion/comment/32359
The code that I have suggested, enforces a validation via JS and hence you can use it along with your timer. However, it is not compatible with the Qualtrics validaiton.


Leave a Reply