Putting numbers up front for scale questions

When projects are imported from the SPSS file the questions can have a format that looks like this: 

Protobi's Edit format dialog showing a 7-point scale with values 1 through 7. The first value is labeled 'Least valuable 1' and the last value is labeled 'Most valuable 7', demonstrating the default format where numbers appear at the end of labels.

Placing the numbers in the front instead of the back can make the information more readable and visually appealing. 

7 point scale

There are a few ways to do this, you can either edit the format for any question, or use the console.

The following code will move the number to the front, e.g., 'Most Valuable 7' to '7 Most Valuable.'

protobi.getDimensions().forEach(function(dim) { var fmt = dim.get('format'); if (fmt) { for (var key in fmt) { var d =fmt[key].slice(-1); if (d==+d) { console.log(fmt[key]); fmt[key] = d + ' ' + fmt[key].slice(0,-1)}} }})

It can be seen in the console of the below project: 

Protobi project interface showing the browser's developer console at the bottom with JavaScript code visible. The main area displays a medical survey project with navigation tabs and a medical-themed illustration with hexagonal icons. The console shows the JavaScript code for moving numbers to the front of scale labels.

10 point scale

The following code works for 10 point scales because it will move two digit numbers to the front, e.g., 'Excellent 10' to '10 Excellent.' Similar to the code above for 7 point scales, put this code in your console. 

protobi.getDimensions().forEach(function(dim) { var fmt = dim.get('format'); if (fmt) { for (var key in fmt) { var d =fmt[key].slice(-2); if (d==+d) { console.log(fmt[key]); fmt[key] = d + ' ' + fmt[key].slice(0,-2)}} }})

The two sets of code above are examples of how JavaScript can be utilized to efficiently modify your Protobi project.