TX Text Control .NET Server

Javascript: ApplicationField.setTypeName Method

Method|Introduced in 28.0

Description

Sets the field's type name. The type name of a Microsoft Word MergeField is MERGEFIELD, for example. If the type name of the field is changed, its parameters must also be changed.

Syntax

<void> ApplicationField.setTypeName(<string> typeName, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
typeName

The type name.

callback

Optional. Is called when the operation completed.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates ApplicationField.setTypeName in a practical document-editing workflow. It sets the field's type name. The type name of a Microsoft Word MergeField is MERGEFIELD, for example. If the type name of the field is changed, its parameters must also be changed.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const applicationFields = mainText.applicationFields;
    applicationFields.getItem(function(applicationField) {
        if (!applicationField) {
            console.warn("No application field is available at the current input position.");
            return;
        }
    
        applicationField.setTypeName(
            "MERGEFIELD",
            function() {
                console.log("set type name completed.");
            },
            onTxError
        );
    }, onTxError);
}, onTxError);