Piping selected choices and adding 'and' before the last choice | XM Community
Solved

Piping selected choices and adding 'and' before the last choice

  • 6 August 2020
  • 2 replies
  • 2 views

Userlevel 2
Badge +6

I have a question with a set of retailers. If I selected Walmart, Costco and Amazon, how can I pipe them to a question with the 'and' added to it?
Walmart, Costco and Amazon
If I use SelectedChoices, it separates everything by a comma.

icon

Best answer by rondev 6 August 2020, 10:49

View original

2 replies

Userlevel 7
Badge +22

In the question text html view wrap the pipe text with span tag and give a class attribute to it as shown below:
${q://QID509/ChoiceGroup/SelectedChoices}
In the javascript of this question where we are displaying the pipe text, paste the below code:
jQuery(".pipetext").text(jQuery(".pipetext").text().replace(/,([^,]*)$/, " and" + '$1') );

Userlevel 2
Badge +6

Thanks!

Leave a Reply