Help with integrating select2 for implementation of multi-select in Qualtrics survey? | XM Community
Skip to main content

Hi,
I'm trying to integrate select2 into my form to implement multi-select as shown below (where respondents can begin typing responses/scroll through available options and select as many as apply)
Screen Shot 2021-12-07 at 15.44.25.pngI haven't used select2 or Javascript before, so I'm a bit confused on how to implement this. I know I can put the Javascript for including select2 into the 'Edit Question Javascript' section, but I'm not sure:

  • Where/how do I include my actual data for all the options? (Is this also in the Question Javascript box, or somewhere else? If somewhere else, where is that and how do I reference that data from the Question Javascript box?)

  • How do I make sure that the response data for this question properly goes into the Data & Analysis section of my Qualtrics form?

In another question on here (https://community.qualtrics.com/XMcommunity/discussion/comment/41960#Comment_41960), someone said you can put the data for each of your options in a Javascript object, but would that go within the 'Edit Question Javascript' box as well?
For more detail, the Javascript listed on the select2 website (https://select2.org/getting-started/basic-usage) is as follows:
$(document).ready(function() {
$('.js-example-basic-multiple').select2();
});
But, the select2 tutorial (linked directly above) says you should use HTML to encode the option data, so I'm not sure how the above Javascript should be modified to reference a Javascript object instead of an HTML file?
tl;dr what code do I use? where does it go? (thx in advance)

In the source code of the header add the following:

Add a multiple choice, selection box question to your survey. You can add the options you want to include by selecting "Click here to edit choices" and pasting a list into the first option.
Add this JavaScript to the question:
jQuery("#"+this.questionId+" select").select2({
placeholder: 'Select all that apply',
closeOnSelect: false,
width: '100%'});
});


Hi @dobra021 

I’m trying to use your method to create a question that allows users to select multiple response choices.  I’m trying to understand if Select2 is still a relevant option.  If I choose Answer Type = Allow Multiple Answers, it seems like the code that you mentioned isn’t needed.  Do you know if the code you mentioned works with this answer type?  Also, how can you confirm this option is working as expected?


Leave a Reply