07-01-2022 08:05 AM - edited 07-08-2022 01:41 AM
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;
titEl.setAttribute("value",titleCase(orig));
}
//document.getElementsByName(fromElementID)[0].addEventListener("change", toTitleCase);
toTitleCase();
</script>