Converting Users Input to Title Case

0
Hello, I want to make one of my input fields on a form either convert the sentence into title case, where the first letter of each word is capitalized, or send an error to the user when it is not in title case before they can save the form. Does anyone know how to do this? Thanks!  
asked
2 answers
1

It’s possible in Mendix, but you need less readable logic:

  • Split string into words
  • Loop the words
    • Get the first character
    • Uppercase this character


In my opinion it’s better to create a Java Action and use the WordUtils library with capitalize() or capitalizeFully(). Examples are available here: https://examples.javacodegeeks.com/core-java/apache/commons/lang3/capitalize-words-of-a-string/

You can call the Java Action in an OnChange microflow or just before your save action.

 

 

answered
0

Hi Molly,

You can add an ‘on leave’ or ‘on change’ event on the input field to trigger a microflow. In the microflow you can change the member with the toUppercase() function in combination with substring(). 
So for example if you want to change the word ‘hello’ to your specifications you would do the following:

toUppercase(substring($variable,0,1)) + substring($variable,1)

Also see: https://docs.mendix.com/refguide/string-function-calls

Good luck!

answered