TX Text Control .NET Server

Javascript: DocumentLinkCollection.add Method

Method|Introduced in 28.0

Description

Adds a new document link to the collection.

Syntax

<void> DocumentLinkCollection.add(<string> text, <DocumentTarget> documentTarget, [<RequestDocumentLinkCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
text

Visible text of the link.

documentTarget

The link target.

callback

Optional. Receives the added document link or null if no link could be added.

errorCallback

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

Examples

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

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

function add(documentTarget) {
    TXTextControl.textParts.getMainText(function(mainText) {
        const documentLinks = mainText.documentLinks;
        documentLinks.add(
            "Quarterly report",
            documentTarget,
            function(result) {
                if (!result) {
                    console.warn("No document link was returned.");
                    return;
                }
                
                console.log("add result:", result);
            },
            onTxError
        );
    }, onTxError);
}