Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How can I use a script in a Livecycle Designer form, to force display of text in Title Case?

Avatar

Former Community Member

Hello,

I am a 'novice' who is DIY'ing the construction of a dynamic pdf form, using Adobe Livecycle Designer 7 (I know, it's a VERY old version!)

[So, any help that comes along must be 'for Idiots'!]

I need to construct a code (Java script?) so that a few of my text-fields DISPLAY data in Title Case - IRRESPECTIVE of how the user types in the data.

So, for example, in a "Address" text-field...

If someone types in ..

"205 sherborne avenue"

- OR -

"205 Sherborne avenue"

- OR -

"205 SHERBORNE AVENUE"...

I need the data to be DISPLAYED ESSENTIALLY as...

"205 Sherborne Avenue".

I found the following code online, and tried it in the 'exit' event of the field I need to modify (with 'language' selected as JavaScript)...

<   this.rawValue = this.rawValue.replace(/\b([a-z])/g, function (_, initial) {return initial.toUpperCase();});   >

... This did convert all the 'initial' letters of the words to Upper Case - AS LONG AS they were not ALL typed in Upper Case!

So, that code worked for the first two of my samples for Sherborne Avenue above - but it did NOT work for the last one...

That is, "205 SHERBORNE AVENUE" did NOT get converted to Title Case - which is what I need help with.

Thanks in advance...

1 Accepted Solution

Avatar

Correct answer by
Level 8

I split this into multimuple lines but you could likely do it in one if you prefer

var sometext = this.rawValue;

sometext = sometext.toLowerCase();

this.rawValue = sometext.replace(/\b([a-z])/g, function (_, initial) {return initial.toUpperCase();});

View solution in original post

6 Replies

Avatar

Correct answer by
Level 8

I split this into multimuple lines but you could likely do it in one if you prefer

var sometext = this.rawValue;

sometext = sometext.toLowerCase();

this.rawValue = sometext.replace(/\b([a-z])/g, function (_, initial) {return initial.toUpperCase();});

Avatar

Level 6

Is there anyway to make exceptions for acronyms? Like USA?

Avatar

Former Community Member

Hey TundraSteve,

Thanks a tonne!

Works perfectly!!!

In fact, your solution is so elegant and direct, that even I am beginning to get a sense of how it works... I have looked at LOTS of similar codes in the past few days, but was not at all getting a sense of how they are working! But comparing your solution with the earlier one I mentioned, I am beginning to get a sense of things!

Any suggestions for what I should read-up in order to understand this king of coding?

I have basically been using the built-in 'Help' - and, trial-and-error - and I have designed my first form - a pretty elaborate one, actually!

So, it would be great if you could guide me through the 'learning curve' a bit!

[I have figured-out the 'basics' - that is, I can lay out the form, use 'if-expressions' (FormCalc), trigger events, even build Subforms that are hidden but 'appear' when triggered by other actions, and so on. What I can't figure out are the various 'code languages' (syntax?) that are being used - like " var sometext", for eg.!]

Cheers, and thanks again!

Avatar

Level 8

Items like var sometext is standard Javascript and there are plenty of tutorials that aren't Adobe specific.  For LiveCycle specific functions the intellisense helps and there are several blogs out there like http://blogs.adobe.com/formfeed/ that will help.