DS Server

Javascript: EditableRegionCollection.add Method

Method|Introduced in 28.0

Description

Adds a new editable region to the document. Its position is defined through the start and length parameters. If the editable region's length is zero, the current text selection is used to define the position.

Syntax

<void> EditableRegionCollection.add(<string> username, <number> id, <number> start, <number> length, [<AddEditableRegionCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
username

The name of the user who can edit the region.

id

The editable region's identifier.

start

Specifies the index (one-based) of the first character which belongs to the editable region.

length

Specifies the number of characters which belong to the editable region.

callback

Optional. The callback function that receives the added editable region.

errorCallback

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

Examples

The following example grants a user access to a deterministic text range and reports the resulting region.

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

TXTextControl.textParts.getMainText(function(mainText) {
    mainText.editableRegions.add("jsmith", 25, 1, 18, function(response, addResult) {
        response.editableRegion.getUserName(function(userName) {
            console.log("Editable region added:", {
                id: 25,
                userName: userName,
                result: addResult
            });
        }, onTxError);
    }, onTxError);
}, onTxError);