Is there a way to do this using JavaScript?
I also want to automatically display thousands separators, so that it is easier to check large numbers.
Cheers,
Patrick
Best answer by TomG
View originalBest answer by TomG
View originalHi all,
I am also trying to add comma separators to a single text input box. I understand that we need to added the following script to the Java for that question:
var cleave = new Cleave('.InputText', {numeral: true, numeralThousandsGroupStyle: 'thousand'});
But I am really struggling with how to add the following portion to the header:
script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cleave.min.js">
Can someone help me with the steps needed to navigate to where this needs to be input? The portion of the text that says "email protected" I am supposed to leave that as is?
Is it possible that since I am using a corporate account that the ability to add script to my header to locked / removed?
Thanks in advance!
https://www.qualtrics.com/community/discussion/comment/33471#Comment_33471The Qualtrics Community replaces anything that look like an email address with "[email protected]". Since the url contains an @ a portion of it gets replaced. Go to https://www.jsdelivr.com, search for cleave, select the file you need and jsdelivr will provide the url you need to copy. Make you are in source mode (<>) when you paste it into the header.
TomG - Thanks that works!
But I do now have the issue that I am not able to convert the Input text to a number upon page completion. I do math with the input on the next page and I want to embed it as a numeric value.
Here is my script:
Within "addonload" I have:
let purchaseinput = new Cleave('.InputText', {numeral: true, numeralThousandsGroupStyle: 'thousand'});
Then within "addOnPageSubmit" I have:
let purchaseamountq = jQuery("#"+this.questionId+" .InputText") ;
let purchaseamountnum = parseFloat(purchaseamountq.replace(/,/g, ""))
Qualtrics.SurveyEngine.setEmbeddedData("Purchased", purchaseamountnum);
The embedding worked before I added the cleave functionality and the parse. I am wondering if it is my retrieving of the input (i.e., JQuery) that might not be working now that I have the cleave added.
Welcome any help on what my issue might be.
Thanks
I don't know why that didn't work, but you should use the cleave function getRawValue.
It's possible the problem is on the next page where you pipe and parse the value.
https://community.qualtrics.com/XMcommunity/discussion/comment/2682#Comment_2682I initially did these steps (the header part) as well as putting the second step in the question add on load but it was not resulting in commas coming automatically for the text being entered. later I realized the inputtext has to be adjusted to match the field with one additional step and then it worked. Might need to try on a multi input question later but atleast for 1 input it worked.
Thank you so much for this amazing thread. It was so clear.
I have a couple questions with more than one answer box. Right now, the commas only appear for the first box. Do you know how I can amend the code so that the commas appear for each box?
Gratefully,
Andrew
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.