TX Text Control .NET Server

Javascript: TextFieldCollection.addWithText Method

Method|Introduced in 30.0

Description

Adds a new TextField with the given text to the collection.

Syntax

<void> TextFieldCollection.addWithText(<string> text, [<RequestTextFieldCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
text

The initial field text.

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.addWithText in a practical document-editing workflow. It adds a new TextField with the given text 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.addWithText(
        "Quarterly report",
        function(field) {
            if (!field) {
                console.warn("No text field was returned.");
                return;
            }
            
            console.log("add with text result:", field);
        },
        onTxError
    );
}, onTxError);