Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

capitalize first letter in text field

Avatar

Level 5

Hi All.

I design form in LiveCycle and I would like capitalize first letter in Last Name text field. Could someone let me know how to capitalize it in JavaScript?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 7

I think I finally got this to work. On the Exit event for the field I put:

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

this forces the first letter of each word to UpperCase

View solution in original post

5 Replies

Avatar

Level 10

Hi,

You could add the following JavaScript code in the exit event of your text field.

if (!this.isNull)

{

    this.rawValue = util.printx(">?<*",this.rawValue);

}

This changes the first character (represented by the ?) to uppercase (represented by the >) and all trailing characters (represented by the *) to lowercase (represented by the <). If you need to do the same hyphenated names or Van Der Valk's and the like you can try this JavaScript in the exit event;

function toTitleCase(textValue) {

    return
textValue.toLowerCase().replace(
/\b[a-z]/g, function replacer(match) { return
match.toUpperCase(); });

}  

if (!this.isNull)

{

  
this.rawValue
= toTitleCase(this.rawValue);

}

Regards

Bruce

Avatar

Level 7

Something is not correct. I get a return value of Empty

Avatar

Level 5

Hi Bruce. Thanks for replay.

Is possible to capitalize all words in Last Name if it contains: space, hyphen, single quote or combination of letters and those characters? If yes. Can you show how to do it?

Thanks.

Avatar

Level 7

If you just want to force everything to upper case then just put this on the fields change event:

xfa.event.change=xfa.event.change.toUpperCase();

Avatar

Correct answer by
Level 7

I think I finally got this to work. On the Exit event for the field I put:

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

this forces the first letter of each word to UpperCase