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

Making rawValue text data appear as Upper Case, Sentence case etc

Avatar

Level 4

This is hopefully a simple one.... but i have not figured it out after a few hours so any help would be great

i want to take rawValues from text fields and use them in various places

so imagine

FirstName.rawvalue = "steve" and Surname.rawValue = "Brown"

I want to be able to use FirstName and Surname with other text as either forced Caps or forced sentence case or whatever

A working example being,

"This book is owned by " + Firstname.rawValue (++somehow caps++) + Surname.rawValue (++somehow caps++) +" please return if found"

to produce

This book is owned by STEVE BROWN please return if found      

But also to be able to use those values to produce "Steve Brown" elsewhere

is there some way to apply uppercase/sentence case/lower case to a value like this by JAVAscript?  

thanks

1 Accepted Solution

Avatar

Correct answer by
Level 6

By using .toUpperCase() method in javascript we can get strings in required formats.

*****.toUpperCase(); // gives whole string in Upper Case

*****..substr(0,1).toUpperCase()+""+*****..substr(1);//gives first character to upper case then add rest of the string.

Please find the attached sample.

RAGHU.

View solution in original post

13 Replies

Avatar

Correct answer by
Level 6

By using .toUpperCase() method in javascript we can get strings in required formats.

*****.toUpperCase(); // gives whole string in Upper Case

*****..substr(0,1).toUpperCase()+""+*****..substr(1);//gives first character to upper case then add rest of the string.

Please find the attached sample.

RAGHU.

Avatar

Level 4

Thanks thats just what I was after.

Avatar

Level 4

hi, Raghu

One quick question, how would you change the code you have so that the output Uppercase and Sentence, instead of being put into text fields are stored as variables so that they can be reused all over the place

i tried changing it like

var uC = this.rawValue;

if(!isEmpty(uC)){

uC.toUpperCase() = var NameUpper;

uC.substr(0,1).toUpperCase()+""+uC.substr(1) = NameSentence;

}

}

but that broke it, and also i tried defining the variables above tat level, so var Nameupper = firstnameupper.rawvalue but that breaks when the field firstnameupper is removed.

any suggestions would be much appeciated

thanks

Avatar

Level 6

In sample i just place to one text field.

In ur case make those as functions, where ever need just call that functions so it will return the required format.

Check the attached sample. These functions under script variables named as js. Also first text field exit event i am calling those functions.

RAGHU.

Avatar

Level 4

hi Raghu,

I tried to reproduce (learn by copying) what you did, so i did this form

(attached) but something is wrong, i think with how i did the variables

any idea what i did wrong, i clicked file, form properties named it js and

added the script - but it looks different in the heirachy for some reason

thanks so much for the help

Avatar

Level 6

No attachement in ur previous post.

Avatar

Level 4

sorry, must have hit a filter, this is the file

thanks

Avatar

Level 6

In ur file script object and code for js is missing. please check the attached updated file.

RAGHU.

Avatar

Level 4

that's really weird,

i'm clicking file, form properties, variables  - hitting the green +, adding name, say "dog" adding value, say "woof"

but that does not go into heirachy right.... cant be accessed... i added your code (thanks for it) like that, and it does not stick..... really confused

Avatar

Level 6

That is the way to create script variable which can be access any where in the pdf.

But here we are creating script object.

right click on variables on hirachy tab then click on insert script object and re-name the script object to js. copy the code to top window when selected the new created object, it will solve ur problem.

Avatar

Former Community Member

Useful script.

I was wondering if it is posible to extend the script to set each first character of a word to upper case and the rest to lower case, if there are several words in the field

i.e. ”james brown” will be set to ”James Brown”

and “JAMES BROWN” wil be set to”James Brown”

I tried this:

uC.substr(0,1).toUpperCase()+""+uC.substr(1).toLowerCase();

But this only sets the first character to upper case and the rest of the field to lower case. How do I acces the next word?

Kirstine