Highlight Question type inside a Loop & Merge block | XM Community
Skip to main content
Solved

Highlight Question type inside a Loop & Merge block

  • December 9, 2021
  • 7 replies
  • 42 views

Forum|alt.badge.img

 I have a question about using a Highlight question inside a Loop&Merge block.
When I place the L&M field ${lm://Field/1} in the highlight text box it treats it as a literal and not a L&M variable. Is there a way to do what we want (JS or otherwise)?

Best answer by TomG

Yes, you have to use JS to change the contents.

7 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • December 10, 2021

Yes, you have to use JS to change the contents.


Forum|alt.badge.img
  • Author
  • December 10, 2021

Hi Tom--
Thanks for getting back to me!
I used this script to write a Loop & Merge variable to my Highlight Q placeholders ".":
Qualtrics.SurveyEngine.addOnReady(function () {
  var $this = jQuery(this.questionContainer);
var test_text = "${lm://Field/1}";
  var choices = test_text.split(" ");
  jQuery(".QuestionBody .HLTextWords .HLTextWord", $this).each(function (i) {
    jQuery(this).text(choices[i].trim());
  });
});
However, as you can see from the below screenshot, "${lm://Field/1}" loses its formatting from being 4 paragraphs to all being joined together (and includes some html tags!) , AND there is a series of trailing "." HLTextWord "boxes".
Is there any way to remedy these two remaining issues?

image.png


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • December 11, 2021

https://community.qualtrics.com/XMcommunity/discussion/comment/42332#Comment_42332You should replace the


tags with spaces before splitting the string.
  • You should hide a span if you don't have a word to put in it


  • Forum|alt.badge.img+1
    • September 25, 2022

    https://community.qualtrics.com/XMcommunity/discussion/comment/42332#Comment_42332Hi Graeme,
    Thank you so much for sharing your code.
    I also tried to incorporate the loop-and-merge sentences in the "edit this highlight text" field, and I used your JS code, but it does not work for me. In the preview it basically shows me a blank field and nothing to highlight. Can I ask you whether you somehow defined the Embedded data or did anything else besides this js code?
    Thanks!


    Forum|alt.badge.img
    • Author
    • October 2, 2022

    Hi OG--
    I put the L&M sentences in the L&M field window(s)
    I put periods separated by single spaces in the "edit this highlight text" field, i.e: . . . . . . . . . .
    When I previewed I made sure I used "Preview" and not "Preview Block".
    I was not able to do any formatting (carriage returns, etc.) nor hide the "extra' spans as Tom suggested, although I tried to, with the last line of the below code:
    Sorry I can't be of more help!
    (Screenshots below the code)
    Qualtrics.SurveyEngine.addOnReady(function ()
      var $this = jQuery(this.questionContainer);
      var test_text = "${lm://Field/1}";
      var choices = test_text.split(" ");
      jQuery(".QuestionBody .HLTextWords .HLTextWord", $this).each(function (i) {
        if(choices[i]) { jQuery(this).text(choices[i].trim()); }
        else { jQuery(this).hide; }
      });
    });
    Highlight Q Screenshots.png


    TomG
    Level 8 ●●●●●●●●
    Forum|alt.badge.img+27
    • Level 8 ●●●●●●●●
    • October 2, 2022

    Forum|alt.badge.img+1
    • October 3, 2022

    Thanks a lot, both of you! Yes, indeed, TomG resolved my issue in a separate thread! Thanks!