Created
January 19, 2022 23:04
-
-
Save penalosa/aef2c0ee7a6020b5976cb7883e00890c to your computer and use it in GitHub Desktop.
Support inline dropdown in Qualtrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Qualtrics.SurveyEngine.addOnload(function() | |
{ | |
this.hideChoices(); | |
const alreadySelected = this.getSelectedChoices()[0] | |
this.getQuestionTextContainer().innerHTML = this.getQuestionInfo().QuestionText.replace( | |
"{{dropdown}}", "<select required name=\""+this.getQuestionInfo().QuestionID+"\" id=\""+this.getQuestionInfo().QuestionID+"-select\"><option value=\"\" disabled "+(!alreadySelected?"selected":"")+" hidden></option>"+Object.values(this.getQuestionInfo().Choices).map(c => "<option "+(alreadySelected ==c.RecodeValue?"selected":"")+ " value=\""+c.RecodeValue+"\">"+c.Text+"</option>").join("\n")+"</select>" | |
); | |
this.getQuestionTextContainer().querySelector("select").addEventListener('change', e => { | |
let option = e.target[e.target.selectedIndex] | |
this.setChoiceValueByRecodeValue(option.value, option.text) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment