TX Text Control .NET Server

Javascript: FormFieldCollection.addTextFormField Method

Method|Introduced in 28.0

Description

Adds a new TextFormField.

Syntax

<void> FormFieldCollection.addTextFormField(<Number> emptyWidth, [<RequestTextFormFieldCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
emptyWidth

Specifies the horizontal extension, in twips, of the TextFormField, when there is no text. When this parameter is set to 0, a default value is used.

callback

Optional. Receives the added TextFormField.

errorCallback

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

Examples

The following example demonstrates FormFieldCollection.addTextFormField in a practical document-editing workflow. It adds a new TextFormField.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const formFields = mainText.formFields;
    formFields.addTextFormField(
        1440,
        function(textFormField) {
            if (!textFormField) {
                console.warn("No text form field was returned.");
                return;
            }
            
            console.log("add text form field result:", textFormField);
        },
        onTxError
    );
}, onTxError);

Further Reading