TX Text Control .NET Server

Events

Topic

Is the editor ready? Has a document been loaded, or has the user changed a field, a tracked change or the input position? The events of the Document Editor's JavaScript API tell your code, each with its own arguments, and the event lists show which event to listen for.

The events belong to the TXTextControl object; JavaScript API explains the object and where it is available in each frontend.

Attach and Remove Event Handlers

addEventListener attaches a function to an event. The function receives an event argument object, or nothing, depending on the event:

TXTextControl.addEventListener("documentLoaded", function (e) {
  console.log("Document loaded: " + e.fileName);
});

removeEventListener removes a handler again. Pass the same function that you attached, so give a handler that you want to remove a name instead of writing it inline:

function logInputPosition(e) {
  console.log("Page " + e.page + ", line " + e.line + ", column " + e.column);
}

TXTextControl.addEventListener("inputPositionChanged", logInputPosition);

// Later, when the information is no longer needed
TXTextControl.removeEventListener("inputPositionChanged", logInputPosition);

The event names are strings. Write them exactly as the tables below list them.

Events During Initialization

When a page with the editor opens, the editor raises these events. The blog article Document Editor: Initialization Events, written for version 32.0, shows them in this order for a document that the view loads:

  1. textControlLoaded: the editor is ready, and your code can use the JavaScript API.
  2. documentLoaded: the document that the view passed to the editor has been loaded.
  3. ribbonTabLoaded: once for each tab of the ribbon.
  4. ribbonTabsLoaded: the complete ribbon has been loaded.

In version 32.0, the editor loads the content of the ribbon over a second WebSocket connection while it loads its other resources, so don't rely on this order: change the content only after textControlLoaded, change a document loaded at startup only after documentLoaded, and change the ribbon's HTML elements only after ribbonTabsLoaded.

In Angular and React, the TXTextControl object itself becomes available later, so attach the handlers where the frontend signals it; When the Object Is Available lists the place for each frontend.

Example

The following script logs the events of the initialization and the connection to the browser console. Add it below the editor in Views/Home/Index.cshtml of the ASP.NET Core tutorial, or after the call of TXTextControl.init in a plain JavaScript page:

<input type="button" onclick="stopLogging()" value="Stop Logging" />

<script>
    // A named function, so that it can be removed again
    function logInputPosition(e) {
        console.log("Page " + e.page + ", line " + e.line + ", column " + e.column);
    }

    TXTextControl.addEventListener("textControlLoaded", function () {
        console.log("Text Control loaded");
        TXTextControl.addEventListener("inputPositionChanged", logInputPosition);
    });

    TXTextControl.addEventListener("documentLoaded", function (e) {
        console.log("Document loaded: " + e.fileName);
    });

    TXTextControl.addEventListener("ribbonTabLoaded", function (e) {
        console.log("Ribbon tab loaded: " + e.tabName);
    });

    TXTextControl.addEventListener("ribbonTabsLoaded", function () {
        console.log("Ribbon tabs loaded");
    });

    TXTextControl.addEventListener("webSocketClosed", function (e) {
        console.log("Connection closed: " + e.code + " " + e.reason);
    });

    function stopLogging() {
        TXTextControl.removeEventListener("inputPositionChanged", logInputPosition);
    }
</script>

Open the browser's developer tools and reload the page. The console shows the loading events, one line for each ribbon tab and a line for every move of the cursor until you click Stop Logging.

Event Reference

The tables list the events by subject. The last column links the object that the handler receives. "None" means that the handler receives no arguments.

Initialization and Loading

EventRaised whenHandler receives
textControlLoadedThe editor has been initialized and can be used from codeNone
documentLoadedA document has been loadedDocumentLoadedEventArgs
ribbonTabLoadedA ribbon tab has been loadedRibbonTabLoadedEventArgs
ribbonTabsLoadedThe ribbon and its texts from the server have been loaded completelyNone
ribbonTabIndexChangedAnother ribbon tab has been selectedRibbonTabIndexChangedEventArgs
contentsResetThe whole content has been deleted and all attributes resetNone

Document, Formatting and Input Position

EventRaised whenHandler receives
changedThe content of the document has changedNone
textControlChangedObsolete; use changed—
documentSizeChangedThe size of the document has changedSize
charFormatChangedThe character formatting of the selection or the input position has changedNone
paragraphFormatChangedThe formatting of the selected paragraphs has changedNone
pageFormatChangedThe page format has changedNone
inputPositionChangedThe input position has changedInputPositionChangedEventArgs
inputParagraphChangedThe input position has moved to another paragraphNone
mainTextActivatedThe main text has received the input position from a header, footer or text frameNone
headerFooterActivated, headerFooterDeactivatedA header or footer has received or lost the input positionHeaderFooterEventArgs
textFrameActivated, textFrameDeactivatedA text frame has received or lost the input positionTextFrameEventArgs
focus, blurThe editor has received or lost the focusNone
zoomFactorChangedThe zoom factor has changedZoomFactorChangedEventArgs
textViewLocationChangedThe visible part of the document has movedTextViewLocationChangedEventArgs
contextMenuOpeningA context menu is about to open; the handler can change its itemsContextMenuEventArgs

Clipboard, Pasting and Dropping

EventRaised whenHandler receives
clipboardModeChangedThe clipboard mode has changedClipboardModeChangedEventArgs
clipboardDataTransferStartA transfer of clipboard data startsClipboardTransferStartEventArgs
clipboardDataTransferProgressA packet of clipboard data has been transferredClipboardTransferProgressEventArgs
clipboardDataTransferCompleteThe transfer of clipboard data has completedClipboardTransferCompleteEventArgs
clipboardDataTransferAbortedA transfer of clipboard data has been abortedClipboardTransferAbortedEventArgs
textPastedRTF, HTML or plain text is pasted with Ctrl+VTextPastedEventArgs
textDroppedRTF, HTML or plain text is dropped onto the editorTextDroppedEventArgs
fileDroppedA file is dropped onto the editorFileDroppedEventArgs

The argument objects of textPasted, textDropped and fileDropped have a cancel property.

Images, Frames, Tables and Shapes

EventRaised whenHandler receives
frameSelected, frameDeselected, frameMoved, frameSizedA frame (image, text frame, chart, barcode or drawing) has been selected, deselected, moved or sizedFrameEventArgs
imageCreated, imageDeleted, imageSelected, imageDeselectedAn image has been created, deleted, selected or deselectedImageEventArgs
textFrameCreated, textFrameDeleted, textFrameSelected, textFrameDeselectedA text frame has been created, deleted, selected or deselectedTextFrameEventArgs
chartCreated, chartDeleted, chartSelected, chartDeselectedA chart has been created, deleted, selected or deselectedChartEventArgs
barcodeCreated, barcodeDeleted, barcodeSelected, barcodeDeselectedA barcode has been created, deleted, selected or deselectedBarcodeEventArgs
drawingCreated, drawingDeleted, drawingSelected, drawingDeselected, drawingActivated, drawingDeactivatedA drawing has been created, deleted, selected, deselected, activated or deactivatedDrawingEventArgs
tableCreatedA table without an ID has been created by pasting or by loading a documentTableEventArgs
tableDeletedA table has been deletedTableEventArgs
tableOfContentsCreated, tableOfContentsDeletedA table of contents has been created or deletedTableOfContentsEventArgs
tableOfContentsEntered, tableOfContentsLeftThe input position has moved into or out of a table of contentsTableOfContentsEventArgs

Fields, Links and Regions

EventRaised whenHandler receives
textFieldCreated, textFieldDeletedA text field has been created or deletedTextFieldEventArgs
textFieldClicked, textFieldEntered, textFieldLeftThe user has clicked into a text field, or the input position has entered or left oneTextFieldEventArgs
formFieldCheckChangedA check box has been checked or clearedCheckFormFieldEventArgs
formFieldDateChangedThe date of a date form field has changedDateFormFieldEventArgs
formFieldSelectionChangedAnother item of a selection form field has been selectedSelectionFormFieldEventArgs
formFieldTextChangedThe text of a text form field has changedTextFormFieldEventArgs
removeComboboxThe drop-down list of a selection form field has to be removedNone
hypertextLinkClickedA hypertext link has been clickedHypertextLinkEventArgs
documentLinkClickedA link to a target in the document has been clickedDocumentLinkEventArgs
subTextPartCreated, subTextPartDeletedA subtext part has been created or deletedSubTextPartEventArgs
subTextPartClicked, subTextPartDoubleClicked, subTextPartEntered, subTextPartLeftThe user has clicked or double-clicked into a subtext part, or the input position has entered or left oneSubTextPartEventArgs
editableRegionCreated, editableRegionDeletedAn editable region has been created or deletedEditableRegionEventArgs
editableRegionEntered, editableRegionLeftThe input position has moved into or out of an editable regionEditableRegionEventArgs

Track Changes and Comments

EventRaised whenHandler receives
trackedChangeCreated, trackedChangeDeletedA tracked change has been created or deletedTrackedChangeEventArgs
trackedChangeChangedThe text of a tracked change has changedTrackedChangeEventArgs
trackedChangeStateChangedA tracked change has become active or inactiveTrackedChangeEventArgs
cannotTrackChangeA change can't be recorded as a tracked changeA default message as a string
commentCreated, commentDeletedA comment has been created or deletedCommentEventArgs
commentChangedThe text of a comment has changedCommentEventArgs
commentStateChangedA comment has become active or inactiveCommentEventArgs
commentedTextEntered, commentedTextLeftThe input position has moved into or out of commented textCommentEventArgs

When a tracked change has been deleted, only some properties of its event data are still valid: the kind of change, the user name, the highlight color and mode and the time of the change.

Footnotes and Signature Fields

EventRaised whenHandler receives
footnoteCreated, footnoteDeletedA footnote has been created or deletedFootnoteEventArgs
footnoteReferenceMarkEntered, footnoteReferenceMarkLeftThe input position has moved to or away from a footnote reference markFootnoteEventArgs
footnoteSectionActivated, footnoteSectionDeactivatedThe footnote section of a page has received or lost the input positionNone
signatureFieldCreated, signatureFieldDeleted, signatureFieldSelected, signatureFieldDeselectedA signature field has been created, deleted, selected or deselectedSignatureFieldEventArgs

Proofing

EventRaised whenHandler receives
spellCheckTextText has changed and its spelling needs to be checkedSpellCheckTextEventArgs
hyphenateWordA word doesn't fit into the line and needs to be hyphenatedHyphenateWordEventArgs

Connection and Errors

EventRaised whenHandler receives
webSocketClosedThe WebSocket connection to the server has been closedWebSocketClosedEventArgs
reconnectionFailedThe editor couldn't reconnect to the serverReconnectionFailedEventArgs
unhandledErrorAn error is about to be thrownErrorArgument

Architecture explains what happens when the connection is lost and how the editor reconnects.