Automatically make the first letter capital and the rest of the word lowercase - InfoPath Dev
in

InfoPath Dev

Qdabra® Training

Use our Google Custom Search for best site search results.

Automatically make the first letter capital and the rest of the word lowercase

Last post 12-09-2011 04:42 PM by Skarn. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-07-2011 04:35 PM

    Automatically make the first letter capital and the rest of the word lowercase

    Hi, How do I go about changing the first letter of a word to be capatalized and the rest of the word lowercase?

     For example: changing "JOHN SMITH" or "john smith" to "John Smith" in a text box.

    Please help!

  • 12-07-2011 05:07 PM In reply to

    Re: Automatically make the first letter capital and the rest of the word lowercase

    That will be tricky using simply xpath expressions.  Here is what I came up with that will take you half the way there:

    concat(translate(substring(field1, 1, 1), "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), translate(substring(field1, 2, string-length(field1)), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"))

    Let me explain the concepts in the this expression:

    • translate(string, find, replace) - there is no convert text to upper or lowercase function.  This is the workaround.  To uppercase a word, I'm basically looking or all the lowercase letters and replacing them with the corresponding uppercase letter.
    • substring(string, start, length) - I'm getting the first character and make it uppercase, then I'm taking the rest of the string and making it lowercase.
    • concat(string, string) - and finally I'm putting the two strings together

    This solution will only work for the single word case, but hopefully can get you started in building the right expression for your solution.

    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 12-08-2011 02:28 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Automatically make the first letter capital and the rest of the word lowercase

    I've never tried this before, and it did seem to take a mess of rules. There might be a better way :-) But attached is an example of field that has this behaviour.

    It uses SPACE as the word separator and it will fail with an error if there's more than 4-5 spaces in the field. Hopefully this will be enough for most situations.


  • 12-09-2011 10:17 AM In reply to

    Re: Automatically make the first letter capital and the rest of the word lowercase

    It works! Thank you both for your help!

  • 12-09-2011 02:43 PM In reply to

    Re: Automatically make the first letter capital and the rest of the word lowercase

    Hi Skarn,

     What if some of my text boxes will only be filled in by one word and there won't be a SPACE in the text boxes?

     

  • 12-09-2011 04:42 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Automatically make the first letter capital and the rest of the word lowercase

    Added another rule at the very beginning to cater for this.

    There is a key method I've used to accomplish this. It resolved a problem you can get if you try to set a fields value using a rule on the field itself.

    Infopath checks and runs the rules on a field immediately after it gets changed, so it can get stuck in an infinite loop (which it breaks by giving the user an error).

    The new rule I've added at the beginning is the simplest example of the method to work around the infinite loops issue so that the rule only runs once after the initial field change.

    'flag field' = 'resting state value' as default
    Change Field -> Run rule if 'flag field' is 'resting state value' -> Rule changes 'flag field' to 'processing state value' -> Rule changes field value -> (A) Infopath runs rules from beginning (as field just changed again) -> Rule does not run this time as 'flag field' is currently = 'processing state value' -> Infopath returns to (A) and runs next action in rule -> Rule changes 'flag field' back to 'resting state value' -> Rules finish.

    'flag field' = 'resting state value' again ready for next field change.

    Might be a bit hard to get your head around but in an extreme usage allowed me to create the mess of rules with produced the desired outcome you asked for ;-)

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.