TX Text Control .NET Server

Javascript: TextFieldCollection.add Method

Method|Introduced in 28.0

Description

Adds a new TextField to the collection.

Syntax

<void> TextFieldCollection.add([<RequestTextFieldCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
callback

Optional. The callback function that receives the requested value.

errorCallback

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

Examples

The following example demonstrates TextFieldCollection.add in a practical document-editing workflow. It adds a new TextField to the collection.

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

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