Table of Contents
cleaveCSM - Format numbers as they are typed in a constant sum matrix question
The cleaveCSM function uses cleave.js to automatically format numeric fields with thousand separators, decimals, currency symbols, etc. in a constant sum matrix. Since a constant sum matrix doesn't accept non-numeric inputs (i.e., formatted numbers) cleaveCSM converts the formatted numbers to numeric behind the scenes.
This function is available for a reasonable fee. Contact TomG on the Qualtrics Community to learn more.
Set-up Instructions
Survey Header
Add the cleaveCSM function to the survey header to make it available to any question in the survey. Go to Look & Feel → General → Header edit → and paste the provided cleaveCSM function JS:
<script>/*Paste cleaveCSM function JS here*/</script>
Alternatively, paste the cleaveCSM function JS into a question's JS outside the existing Qualtrics functions to make it available to questions on the page.
Question JavaScript
Add JS to call the cleaveCSM function to apply it to the constant sum matrix question as follows:
Qualtrics.SurveyEngine.addOnload(function() { cleaveCSM(this); });
To override default options, add an object containing the options to the function call. For example:
Qualtrics.SurveyEngine.addOnload(function() { cleaveCSM(this,{cleaveparms:{prefix:"$"},placeholder:"$0"}); });
Options
align
align specifies the alignment of the number within the text entry box. Possible value are "left", "right", and "center".
Default: "right"
cleaveparms
cleaveparms is an object that specifies the cleave parameters. See cleave.js for more details.
cleaveparm: delimiter
The thousands separator as a string.
Default ","
cleaveparm: prefix
The number prefix as a string, such as a currency symbol.
Default: "" (none)
cleavparm: noImmediatePrefix
Boolean to not show prefix until a number is entered.
Default: true
cleaveparm: numeralIntegerScale
The maximum number of digits allowed before the decimal.
Default: 10
cleaveparm: numeralDecimalScale
The maximum number of decimal places allowed.
Default: 0
cleaveparm: numeralDecimalMark
The decimal symbol as a string.
Default: "."
cleaveparm: numeralPositiveOnly
Boolean to allow positive numbers only.
Default: true
cleaveparm: stripLeadingZeros
Boolean to strip leading zeros from numbers.
Default:true
fixedDecimal
Boolean to record number with a fixed number of decimal places. Number of decimal place matches numeralDecimalScale.
Default: false
selector
CSS style selector for input boxes to format (e.g., specific columns). If empty, all constant sum input boxes are formatted.
Default: "" (empty)
width
The width of the input boxes. If empty, the question's default width is used.
Default: "" (empty)
zeroBlank
Boolean to show zeros (the default input value in constant sum matrices) as blank.
Default: false