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

Bold only part of text field populated by JavaScript?

Avatar

Level 1

I am using a drop-down box to populate a text field, as in this example. It works fine, but I am having trouble formatting the output. I need to bold only a portion of the text. I don't know very much about scripting, so I am stuck. I tried to connect two strings together, with the JavaScript method for bold text on the second string, like so:

TextField1.rawValue = "Some plain text!\n" + "Some bold text!".bold();

Both strings show up, but instead of the second being bold, it just outputs the HTML tags for bold, so in my text field I get this:

Some plain text!
<b>Some bold text!</b>

The text field format is set to rich text and the data format is set to xhtml since users also have the ability to add their own answers to the text field as well. However, I don't want them to have to select and bold text that is automatically sent to the text field by the drop-down list. It kind of defeats the purpose of automating it in the first place if they have to go back and adjust it every time...

Is there something I'm missing? Or another, better way to do this? Any help is greatly appreciated.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

I wrote a blog entry recenly on how to get Rich text to work correctly in PDF form fields. Have a look at that at http://livecyclekarma.wordpress.com/2009/05/20/richtext-tricks-for-textfield-in-designer/

regards,

Parth Pandya

Blog: http://livecyclekarma.wordpress.com

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

Hi,

I wrote a blog entry recenly on how to get Rich text to work correctly in PDF form fields. Have a look at that at http://livecyclekarma.wordpress.com/2009/05/20/richtext-tricks-for-textfield-in-designer/

regards,

Parth Pandya

Blog: http://livecyclekarma.wordpress.com

Avatar

Level 1

Thank you, that was exactly what I was looking for. The example PDF you included in your blog entry was very helpful too.

Avatar

Level 2

Do you still have the example of how to do this? The answer above is no longer available.

Avatar

Level 10

Hi there,

 

if you wish to achieve something similar to the initial post of this thread follow the instructions:

 

First ensure that your field contains Rich Text, if your field is in fact a text field you have to change the field format in Object palette to match Rich Text instead of Plain Text.

Magus069_0-1644727735321.png

 

Afterwards, if you wish to change the value of the field with specific rich text format, you must have an XML version ready to implement in the field. Any XML version is available to you if you copy the xml data from a text label object which has rich text in it, and you can start from there.

Technically the basic values of an XML format you must use is the following:

<body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\"><p style=\"text-decoration:none;letter-spacing:0in\"> Insert HTML with CSS as you wish </p></body>

So, to achieve something like this initial post wanted to do, you can do it like this:

var strInsertText = "Some plain text!<br/>" + "Some bold text!".bold(),
	strXML = "<body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\"><p style=\"text-decoration:none;letter-spacing:0in\">" + strInsertText + "</p></body>";
this.value.exData.loadXML(strXML);

Note that "this" variable is the field object that I'm changing its value, but for a simple demonstration I'm doing it in the initialize event.

 

I hope this will help, don't hesitate if you have any questions.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----