This month's Badge of the Month 💬 discussion is about your favorite spooky entertainment! Tell us about your favorite spooky movies, books, and more to earn your badge now | EARN BADGE >

Replacing comma with line break in piped text

BarbiUF
BarbiUF FL, USA
edited July 2021 in Custom Code

Good afternoon. I'm trying to replace the usual comma with line breaks after each selection (piped in text using show selected) in a trigger email. I've tried a couple of different things but that just led me to realize I need to get some coding classes under my belt ASAP. Here is what I'm working with:

  • You will be assessing students’ performance on the following outcome(s):
  • ${q://QID18/ChoiceGroup/SelectedChoices}

They show up in the email like this:

You will be assessing students’ performance on the following outcome(s):

  • Outcome 6: Experiments, Outcome 7: New knowledge

What can I add to the piped text to make that comma a line break so they show one right under the other - like this:

You will be assessing students’ performance on the following outcome(s):

  • Outcome 6: Experiments
  • Outcome 7: New knowledge

Any help would be greatly appreciated. Any recommendations on coding courses to start with would be appreciated too! :)

Answers

  • ahmedA
    ahmedA India Level 6 ●●●●●●
    edited December 2020

    In JS, import the piped text and then replace the comma with the line break tag <br>

    Then store it back to an embedded variable and use this variable instead of answer choices.

  • BarbiUF
    BarbiUF FL, USA

    @ahmedA Would you mind showing me what that would look like? I've never used this before. I was trying to use the javascript option by entering this but it doesn't work. I'm pulling in the string of student data (last name, first name, email that sort of thing)

    Qualtrics.SurveyEngine.addOnReady(function()

    {

    var textElements = this.questionContainer.select('.CommaReplacement');  

      var newDelimiter = "<br>"


      for(var i = 0; i<textElements.length; i++){

        var temp = textElements[i].innerHTML;

        console.log(temp);

        temp = temp.replace(new RegExp(", ", 'g'), newDelimiter);

        console.log(temp);

        textElements[i].innerHTML = temp;

    }

    });


    Qualtrics.SurveyEngine.addOnUnload(function()

    {

    var textElements = this.questionContainer.select('.CommaReplacement');  

      var newDelimiter = "<br>"


      for(var i = 0; i<textElements.length; i++){

        var temp = textElements[i].innerHTML;

        console.log(temp);

        temp = temp.replace(new RegExp(", ", 'g'), newDelimiter);

        console.log(temp);

        textElements[i].innerHTML = temp;

    }

    });

  • Diwere
    Diwere Massachusetts

    @BarbiUF - I'm having a similar issue. Would you mind sharing what you did to solve this problem?