How to add custom text to slider tooltip? | XM Community
Solved

How to add custom text to slider tooltip?


Hello Everyone,
I am trying to create a survey where respondents use a slider to provide their choice.
image.pngAs one moves the handle along the slider the choices are (1,2,3,4,5) are shown respectively on the tooltip.
image.pngHow can I show custom text in the toolTipBox instead of the choice selected. With respect to the above image, how can I show "customized text" in the box instead of one?

icon

Best answer by TomG 7 May 2020, 14:04

View original

17 replies

Userlevel 5
Badge +11

Hi JohnnyP10,
Thanks for the post here. I think (!) I'm looking for the same solution but don't really understand completely how this is used. Does the mutationobserver function need a ref to an external url (by putting something in the Look and Feel / Header)?
I'm looking to replace the value that appears in the tooltip when you slide the slider with whatever equivalent label there is (or based on another set of labels).
How do I implement this - I'm assuming that you use the above code but I'm not sure is you add this to the onload / onready section.
Please can you advice or if possible provide a simple example survey file?
Thanks in advance
Rod Pestell

Badge

it took me a while to figure out the MutationObserver so adding it here for anyone else
/*Place your JavaScript here to run when the page is fully displayed*/
// Select the node that will be observed for mutations
const targetNode = document.getElementsByClassName("sliderToolTipBox")[0];
let observer = new MutationObserver(function() {
targetNode.innerHTML = Math.abs(targetNode.innerHTML);
observer.disconnect(); // turn observer off;
observer.observe(targetNode, {
attributes: true,
childList: true, // observe direct children
subtree: true, // and lower descendants too
characterDataOldValue: true // pass old data to callback
});// turn back on

});

// observe everything except attributes
observer.observe(targetNode, {
attributes: true,
childList: true, // observe direct children
subtree: true, // and lower descendants too
characterDataOldValue: true // pass old data to callback

});

Userlevel 3
Badge +11

https://www.qualtrics.com/community/discussion/comment/36301#Comment_36301Thanks a lot TomG for this insight. putting the script inside the function Qualtrics.SurveyEngine.addOnload() works well instead of using myInput.onload().

Here below is a thread explaining the full steps about how to change/replace Authenticator's label and set a textbox placeholder...
https://www.qualtrics.com/community/discussion/15597/removing-authenticator-label-and-set-placeholder-for-the-textbox-insteadMany thanks again for your insight TomG ...

Userlevel 7
Badge +27

You should place your script inside the function Qualtrics.SurveyEngine.addOnload(), then you don't need the myInput.onload.

Userlevel 3
Badge +11

https://www.qualtrics.com/community/discussion/comment/36170#Comment_36170Thanks TomG ...
as I checked Authenticator is appearing on the same page load that occur before. I have a question with a page break then Authenticator appears after that. I trace the elements and see that a DOM is inserted not a new page is loaded when i move next to authenticator part..

Anyways, if possible, what is how to getElement of Authenticator textbox in order to apply the functions on Qualtrics.SurveyEngine.addOnload to set the placeholder attribute?

Basically, I was able to change the placeholder attribute of Authenticator onblur and onFocus events as followed but I could not onload event as shown below...



Userlevel 7
Badge +27

That's the basic gist. But the function is Qualtrics.SurveyEngine.addOnload and the Authenticator isn't an element, it is a page.

Userlevel 3
Badge +11


https://www.qualtrics.com/community/discussion/comment/36168#Comment_36168TomG do you mean :

  • creating a new message in the library

  • in the source code of message, Create onLoad function

  • getElementById for Authenticator

  • setAttribute of placeholder for that selected element (Authenticator)

??
as i was inspecting the elements, i saw that the Authenticator DOM is created after loading that's why i thought of MutationObserver. However, if the mentioed points above are correct to apply, i will post a full topic explaining how to change replace Authenticator's lable with a placeholder...

Userlevel 7
Badge +27

Muqaibil - For an Authenticator, use a library message and place the code in there (inside a

Scanning file for viruses.

Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.

OK

This file cannot be downloaded

Sorry, our virus scanner detected that this file isn't safe to download.

OK