Writing formatted text to a Text Field in LC Designer XFA forms

Text fields in XFA forms have a limited support for XHTML markup, allowing rich text text fields in a fillable form.

You can populate these fields using JavaScript, but it requires a bit more trickery than a simple call to field.rawValue

Here’s a script that sets the value of a text field to contain styled text – so long as the text field has its property set to Rich Text

// This is the envelope that the HTML-formatted data needs to be placed in
// remember to escape quote marks

var envel = ‘<?xml version=”1.0″ encoding=”UTF-8″?><exData contentType=”text/html” xmlns=”http://www.xfa.org/schema/xfa-template/2.8/”><body xmlns=”http://www.w3.org/1999/xhtml” xmlns:xfa=”http://www.xfa.org/schema/xfa-data/1.0/” xfa:APIVersion=”Acroform:″ xfa:spec=”2.1″><p style=”margin-top:0pt;margin-bottom:0pt;font-family:\’Myriad Pro\’;font-size:10pt;text-decoration:none”>PLACEHOLDER</p></body></exData>’;

// This is the HTML-formatted data
var jsdata = ‘<b>Hello</b> <i>Stylish</i> <u>World</u>’;

// put the HTML data in the envelope
jsdata = envel.replace(/PLACEHOLDER/g,jsdata);

// Load the XHTML into the field
// the …, 1, 1 arguments are required for exData to understand the content it seems

form1.sub1.TextField1.value.exData.loadXML(jsdata, 1, 1);

To extract the HTML afterwards, you will need to use “saveXML”. To get just the resulting plain text, you can access via rawValue as normal.

And as AnchorMan says: “Stay Stylish San Diego!” :-)

Comments are closed.