Preserving rich text formatting when copying field values

This example demonstrates how to maintain rich text formatting of field data when copying values between fields.

TextField1 and TextField2 are configured to Allow Multiple Lines and display rich text formatting.

The Copy Rich Text button copies the value of TextField1, including rich text formatting, and pastes it in TextField2.

Scripting for the Copy Rich Text button

Rich text field values are stored in XML format within a child object of the field that contains the value. The following script, located on the click event of the Copy Rich Text button, uses the saveXML method to store the XML definition of the rich text value. Subsequently, the XML data is loaded into the corresponding child object of TextField2.

var richText = TextField1.value.exData.saveXML(); TextField2.value.exData.loadXML(richText,1,1);

In this example, the rich text value is set to overwrite the existing value of TextField2. Adjusting the script to the following would append the rich text data to the current value of TextField2:

    var richText = TextField1.value.exData.saveXML(); 
    TextField2.value.exData.loadXML(richText,1,0);

// Ethnio survey code removed