Showing results for 
Show  only  | Search instead for 
Did you mean: 

String capitalisation

Changemaker II

Hi all,

I wonder if anyone has a simple solution for the following. I've found what I think are parts of the answer, but nothing that leads me to a full implementation.

I have some text being returned from a db lookup and it's all in capitals. I want to convert that part of the text into mixed case, each word should start with a capital letter.

I can find suggestions on using an SQL function to achieve this, but also that it should be easier in the product to which the information is returned, which in this case is the Firmstep platform. The text processing calculations I've found don't seem to have anything that translates directly into what I'm after. If anyone has a pointer that would help me out, I would be most grateful.


Changemaker II

I thought there might be a way to achieve this using regex and replaceAll , but couldn't get that to work.

I have found a way to do it which works.  

Pop an HTML Element into your form and paste in the following code  and then edit line 2 and 3 so that fromElementID is the dataname of your field that is all uppercase and toElementID is the dataname of the field that should contain your proper case.  
If your source field is editable then you might want to uncomment the commented out line that adds an event listener to the source field so the function will run whenever it's changed.

as this is a custom javascript solution note that it will not be supported by Granicus 



<script type="text/javascript">
var fromElementID="upprstring";
var toElementID="properstring";

function titleCase(str) {
return str.toLowerCase().split(' ').map(function(word) {
return word.replace(word[0], word[0].toUpperCase());
}).join(' ');
function toTitleCase() {

var upEl = document.querySelector("input[ Name='"+fromElementID+"' ]");
var titEl = document.querySelector("input[ Name='"+toElementID+"' ]");
var orig = upEl.value;

//document.getElementsByName(fromElementID)[0].addEventListener("change", toTitleCase);