DS Server

Javascript: CommentCollection.add Method

Method|Introduced in 30.0

Description

Creates a comment with the specified comment string. The current text selection defines the commented text.

Syntax

<void> CommentCollection.add(<string> comment, [<AddCommentCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
comment

The comment string or null. Use null to open a text input box so that the end-user can type the comment's text for the currently selected text. The new comment is inserted after the text input box has been closed.

callback

Optional. Receives the result of the add operation.

errorCallback

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

Examples

The following example demonstrates CommentCollection.add in a practical document-editing workflow. It creates a comment with the specified comment string. The current text selection defines the commented text.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const comments = mainText.comments;
    comments.add(
        "Please review this section.",
        function(response) {
            if (!response) {
                console.warn("No comment callback data was returned.");
                return;
            }
            
            console.log("add result:", response);
        },
        onTxError
    );
}, onTxError);