Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Converting Text to Its Proper Case

Avatar

Level 2

Looking for a way to convert the text in my text field on my form to proper case when the user tabs out of the field. I would think i could use the javascript to validate this. New to LiveCycle ES. any help would be appreciated , Thanks

Form.png

1 Accepted Solution

Avatar

Correct answer by
Level 10

Place the below code in the exit event with JavaScript to convert the text to proper case.

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

Thanks

Srini

View solution in original post

5 Replies

Avatar

Level 10

The attached contains a repeating subform that manages the case of the partDescription as follows:

// form1.purchaseOrder.detail.partDescription::exit - (JavaScript, client)

if (!(this.isNull || this.rawValue == "")) {

          var str = this.rawValue;

          var char1 = str.substring(0,1);

          var char2_n = str.substring(1,str.length);

          this.rawValue = char1.toUpperCase() + char2_n.toLowerCase();

}

Steve

Avatar

Correct answer by
Level 10

Place the below code in the exit event with JavaScript to convert the text to proper case.

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

Thanks

Srini

Avatar

Level 10

That's slick Srini - could you break it down for me so I can see how it works? How does the first letter get passed to the internal function?

I still have a lot to learn in JavaScript.

Avatar

Level 10

The regular expression is the key here.

/\b([a-z])/g -> will check for all the first character in each word and then pass it to the internal function.

If more than one word is available, then it will call the function that many times.

Thanks

Srini

Avatar

Level 10

I get the regex part (except for the /g) but I'm unsure how it passes the letter to the function, is it the underscore?

Is there a name for this type of statement so I can read up on it?