HH:MM as input - Sample Code | XM Community
Skip to main content

Greetings
I found the following:
https://www.qualtrics.com/community/discussion/913/is-there-a-way-to-have-users-enter-time-hh-mm-for-their-answersMy question is where can I get a working sample of adding of the solution as proposed?
1) Where do I put the JS Library definition
2) Where do I put the code
3) How do I feed the input selected to the survey?

Try putting this JS code in the text input question, hope this helps.
Qualtrics.SurveyEngine.addOnReady(function () {
  var questId = this.questionId;
  var script = document.createElement('script');
  script.onload = function () {
    new Cleave('.QR-' + questId, {
      time: true,
      timePattern: 'h', 'm']
    });
  };
  script.src = "//nosir.github.io/cleave.js/dist/cleave.min.js";
  document.head.appendChild(script);
});


You don't need any external libraries.
In a text entry question, just add this line to your JS.

this.getQuestionContainer().querySelector("input").type = "time";

The input will be stored in Qualtrics just like any other text entry.


Leave a Reply