Moving "Constant Sum" Labels to Left AND Translate | XM Community
Skip to main content
Question

Moving "Constant Sum" Labels to Left AND Translate

  • February 12, 2025
  • 7 replies
  • 32 views

Forum|alt.badge.img+1

The title pretty much says it all.

I have this question:

 

that has this code to move the labels in front of the boxes:

Qualtrics.SurveyEngine.addOnReady(function() {

    // Move the "Today" label in front of the first text field

    const todayLabel = document.createElement('span');

    todayLabel.innerHTML = "Today: ";

    todayLabel.style.marginRight = "10px"; // Add spacing

    const todayField = document.querySelector('input[type="text"]');

    todayField.parentNode.insertBefore(todayLabel, todayField);

 

    // Move the "2030" label in front of the second text field

    const year2030Label = document.createElement('span');

    year2030Label.innerHTML = "2030: ";

    year2030Label.style.marginRight = "10px"; // Add spacing

    const year2030Field = document.querySelectorAll('input[type="text"]')[1];

    year2030Field.parentNode.insertBefore(year2030Label, year2030Field);

});

 

The issue is that the label isn’t dynamic, so it doesn’t adjust to the chosen language. I have 14 languages and no matter what I try, I just cannot get this label to change. I have tried a label-changing code I found here and tried embedding it within the above code, but it either does nothing or returns “false” for all languages. I spent two hours last night arguing with ai about this code and none of its suggestions work. I just asked ai for a unique code that does all that I need it to, and now I have no labels at all.

 

Can someone please help me? I am completely stuck here.

7 replies

  • Level 4 ●●●●
  • 212 replies
  • February 12, 2025

By default, labels in constant sum question will be before the text boxes. I wonder whats exactly the problem is? 


Forum|alt.badge.img+1
  • Author
  • 4 replies
  • February 12, 2025

Sorry. I should have specified that we do not use the sum function for this question, which, for some insanely stupid reason moves the labels to below each box.


  • Level 4 ●●●●
  • 212 replies
  • February 12, 2025

What type of question it is?


Forum|alt.badge.img+1
  • Author
  • 4 replies
  • February 12, 2025
jbk wrote:

What type of question it is?

I’m sorry; I’m not sure what you are asking. It is the question above, in the Constant Sum format with the sum functionality turned off. 

I am currently working with using a form field with coding to add the % behind it. It doesn’t really meet my needs, but it may work in a pinch.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5938 replies
  • February 12, 2025

@DevonMW,

The easiest solution is to turn on “Add Total” then hide the Total row. For non “New Survey Experience” the JS would be:

Qualtrics.SurveyEngine.addOnload(function() {
	jQuery("#"+this.questionId+" .Total").hide();
});

 


  • Level 4 ●●●●
  • 212 replies
  • February 13, 2025
DevonMW wrote:
jbk wrote:

What type of question it is?

I’m sorry; I’m not sure what you are asking. It is the question above, in the Constant Sum format with the sum functionality turned off. 

I am currently working with using a form field with coding to add the % behind it. It doesn’t really meet my needs, but it may work in a pinch.

Correct me if I’m wrong, you are not able to translate the word “today”. Is that right?


Forum|alt.badge.img+1
  • Author
  • 4 replies
  • February 13, 2025

To anyone who helped, I appreciate it. I ended up switching the question to a form field and using code to add the % after the box and prevent wrapping with an additional line of code. (I found this solution in the community.)

The translations were still not showing up, so I did more digging. The issue was not that the code wasn’t working, but that all of the translations for the relevant label had been formatted to be white text, but this wasn’t showing in the exports or the label line. So, after going through each of the translations, changing the text colour and entering the translations, all is working fine.

This is absolutely the dumbest issue I have ever not been able to figure out. On the plus side, I now know several ways to code this issue and I can say “Today” in 13 languages. I really hope vandaag/hoje/heute/hoy/aujourd’hui is a better day. Thank you!


Leave a Reply