Piping selected choices and adding 'and' before the last choice | XM Community
Skip to main content
Solved

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

  • August 6, 2020
  • 2 replies
  • 19 views

Forum|alt.badge.img+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.

Best answer by rondev

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') );

2 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • August 6, 2020

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') );


Forum|alt.badge.img+6
  • Author
  • Level 2 ●●
  • August 6, 2020

Thanks!