Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Bold/Underline/Italic issue in LifeCycle 7.1

Avatar

Former Community Member
Hello everyone!



Wonder if anybody knows how to apply "bold", "underline" and/or "italic" to the text via JavaScript or FormCalc in LifeCycle 7.1.

I'm trying to do logic on a small piece of text that is inside of a paragraph and at one point I need this smaller piece of text to be "bold" and at another point I need it to be "italic".



Any help would be very much appreciated.
23 Replies

Avatar

Former Community Member
Change the following options in your TextField: under Field, change Field Format to Rich Text, and under Binding, change Data Format to XHTML. When filling out the form you can load the Form Field Text Properties toolbar (Ctrl+E) to allow you field formatting, e.g. bold, italic, underline, strikethrough, etc.

Avatar

Former Community Member
Thank you Helen.

I did everything up to "When filling out the form you can load the Form Field Text Properties toolbar (Ctrl+E) to allow you field formatting" point which I don't think I understand.

What sintax should I use in JavaScript or FormCalc in order to force "bold" or "italic" on the text. (Note: it's not a "text field" I'm trying to do logic on but just a "text" object.)



I tried:



this.font.weight = "bold";

this.rawValue = "Hello!";



and also:



this.rawValue = "\bHello!\b0"; (similar to what I used to do in Accelio Output Designer with no any problem.)



Or simply, let's say I have text "Hello World!", what syntax should I use in order to make word "World!" bold?



Thank you very much.



S.E.

Avatar

Former Community Member
Hi Slava,



If I understand your scenario... you have a Text object that you have typed data into it. Within that data you have text that you want formatted to display Bold. You can do that without scripting it.



Select the Text Object and highlight the text you want Bolded. In the toolbar you will see the Bold icon which is displayed by a Big Bold "B". Click it and it will Bold the highlighted Text.



You can do the same for the Italiced text. Just click on the slanted "I" icon from the toolbar.



Hope that helps.

Pam

Avatar

Former Community Member
Hi Pam,



not really... that's not what I'm trying to do.



What I'm tring to do is this...

Let's say I have a piece of text like "It's a beautiful World!".

There are people in the state of NY and in the state of CA who need to see word "beautiful" differently. People in NY need to see it in "bold" whereas people from CA need to see it in "italic".



So my question is, how would I write logic in JavaScript or FormCalc in Adobe LifeCycle 7.1 to accomplish this.



Or something like:



if (state.rawValue == "NY"){

this.rawValue = "It's a beautiful World!";

} else if {

(state.rawValue == "CA"){

this.rawValue = "It's a beautiful World!";

} else {

this.rawValue = "";

}



What else do I need to write (or do) in order to make word "beautiful" bold for the state of NY and italic for the state of CA????

Avatar

Former Community Member
Hi Slava,

I added two textfields (Textfield1 and Textfield2). Set them to Rich Text on the Field Tab and XHtml format on the Binding Tab.

On the click event of TextField2 using Javascript Run at Client. I broke down the phrase you used for both cities into 6 variables. Added the bold() attribute to the Variable for "beautiful".

----- form1.#subform[0].TextField2::click: - (JavaScript, client)
var NY1="It's a";
var NY2="beautiful";
NY2=NY2.bold();
var NY3="World!";
var CA1="It's a";
var CA2="beautiful"
CA2=CA2.italics();
var CA3="World!";

TextField1.rawValue=(NY1+" "+NY2+" "+NY3);
TextField2.rawValue=(CA1+" "+CA2+" "+CA3);

I saved the file as dynamic ver 7 and previewed the form.

I clicked in textfield2 and it populated textfield1 with the string It's a beautiful World!
It adds the and but Adobe doesn't interpret it as bolding the text.

I clicked in textfield1 and it populated textfield1 with the string It's a beautiful World!
It adds the and but Adobe doesn't interpret it as bolding the text. Even though both textfields are set to rich text.

In viewing the XML I see where it shows the Field format


 




In the xfa_spec_2_5.pdf it has a section on Page 188 Representing and Processing RichText. I linked to page 1035 for an example of Bolding text. I defined a variable Pam_A and pasted their example into the script editor.

The second and
fourth
words are bold.



I added a new field and added this script to the click event of TextField2. TextField3.rawValue=(Pam_A);

The TextField3 displays "Empty" on Preview of form.

Perhaps an Adobe support member can shed more light on what the exact code we need to use.

Have a great day.
Pam

Avatar

Former Community Member
Hi Slava,



What I wanted to paste didn't appear in my last posting:

body xmlns="http://www.w3.org/1999/xhtml"

"xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"

"xfa:APIVersion="2.5.6290.0



This is not the version of the xhtml documented to use for xfa 2.5 or 2.4. Page 1091 of the xfa_spec_2_5.pdf.



Perhaps an Adobe support member can shed more light on what the exact code we need to use.



Thanks

Pam



Have a great day.

Pam

Avatar

Former Community Member
Hi Pam,



thanks for your email but that did not help.



I thought syntax like



var v_Word = "Hello!";

v_Word = v_Word.bold();

this.rawValue = v_Word;



would do it, but all it displayed was
Hello! when I ran preview. Also we do not safe forms as "Dinamic PDF form files (.pdf)" but as "Adobe XML Form File (.xdp)".



Just can't understand why would simple thing like bolding or underlining text using the script must be so complicated in Adobe LifeCycle. As I said it a piece of cake to do in Accelio Output Designer. And even if you using simple Java Script like in my sample above it still wouldn't work.



Any other suggestions?

Avatar

Former Community Member
Oh... See, It does work in here... Word "Hello" is in bold now. But why doesn't it work when I ran to preview it in LifeCycle???

Avatar

Former Community Member
Hello Slava,



I can think of two scenarios. First, change the rich text value of a Text object at runtime using the loadXML() method.



For example (hope this will display correctly):



StaticText1.value.exData.loadXML("

Hello

World

");



As you can see, you want to pass the xhtml markup. I can never remember the syntax of xhml so to simplify things, I like to create a Text object, format its value then look up the xhtml in the XML Source.



For example, create a Text object and write Hello World. Then click on the XML Source tab (while the Text object is selected). Look for the xhtml child of the exData element and copy the body tag to the script editor (to use in your script later).



Repeat these steps for the Hello World string.



Now there are some conditions for this scenario to work.



1. The form needs to be rendered as a Dynamic PDF.

2. The Text object needs to be rich text to begin with. I suggest setting the value of the Text object to either format e.g. Hello World.



Another scenario would be to create a Text object for each format i.e. one for Hello World and one for Hello World and show/hide them when the form is rendered. Just write a form:ready script on the parent subform. This scenario works for Static PDF forms.



Hope that helps.



Regards,



Hélène

Adobe Systems

Avatar

Former Community Member
Well, that didn't work out as planned : )



Just to be clear, you must pass the xhtml markup to the loadXML()method i.e. start with the body tag and end with a closing body tag. As mentioned in my previous post, an example can be found in the XML Source.



Hope that makes sense.



Cheers



Hélène

Adobe Systems

Avatar

Former Community Member
Hi Helene,



thanks for an explanation. However I think you forgot to describe as how would I use it in a script.



I tried the following, not sure if that is correct since it gives me syntax error.



this.value.#exData.loadXML("

The undersigned certifies to the best of its

knowledge:

");



Hope it'll display it correctly, but you can look the whole thing up by clicking going View-> Source



Please let me know.



Slava

Avatar

Former Community Member
Slava,



The # sign is a reserved character in JavaScript and will generate a syntax error. Instead try



this.value.exData.loadXML(" xhtml goes here ");



Remember to replace all " with ' in the xhtml in your script.



The view source of my previous message is not quite like I wrote it so I wouldn't rely on it.



Does that answer your question?



Hélène

Adobe Systems

Avatar

Former Community Member
Yes, I tried it without the "#" and it says that "this.value." does not have properties "exData" but "#exData".... I also did replaced all the " with '.



Not sure what else would I do for it to work.

Avatar

Former Community Member
A few questions:



1. Looks like you are using a text field. Is the data and field format set to Rich Text?

2. Can you provide the full error message?

3. Which event of the text field are you using?



Thanks



Hélène

Adobe Systems

Avatar

Former Community Member
Yes, I'm using text field and yes, I set it to Rich Text.

I tried it on "change" and "initiate" events and well few others but that did not make a difference.

As to error message all is says is Syntax error in Java script.

Avatar

Former Community Member
Helene,



Can you please upload a sample for us to view the code? Since we can't copy and paste the script and have it be visible.



Thanks in advance.

Pam

Avatar

Former Community Member
Pam,



I'd be happy to however I can't find an option to upload an image to this thread. Have I missed something? If there isn't a way then I can always try to post the sample on the Developer Center.



Hélène

Adobe Systems

Avatar

Former Community Member
Helene,



I've seen old posts with links to forms. However, with that method the form would need to be available from the internet.



I think it would be best on the Developer Center for all users and post the link to the file.



Thanks again.

Pam

Avatar

Former Community Member
Pam,



Ok, it may take a few days. I'll reply as soon as it becomes available.



Regards



Hélène

Adobe Systems