Adding commas to numeric responses in a matrix table | XM Community
Skip to main content
I have a matrix table where the rows are services, and the columns are number of clients served, units served, and dollars spent (see image for example).



I would like to format the question so that commas appear when the respondents enter their numeric response - so if they enter 3000000 they would see 3,000,000.



I have found this code using Cleave.js and applied it to single text entry question, but I cannot figure out how to make it work within a matrix table. Any help or suggestions would be greatly appreciated!



!
@TraciW You are on the right path. Since we are dealing with a matrix, you would need to insert an array statement at the front of the JS, inserted under the OnLoad section of your question JS.



<code>var inputs = jQuery("input[type='text']");

inputs .toArray() .forEach(function(field)

{

new Cleave(field,

{

numeral: true,

numeralThousandsGroupStyle: 'thousand'

});

});</code>



One thing to be cautious of is the commas will also appear in your data. This means some platforms may read the cell as a string rather than numeric. It could also mess with comma delimited file formats as well. Something to be aware of in case your run into issues.
@C_Bohn This worked perfectly. Thank you so much for your clear explanation and things to watch out for.

Leave a Reply