Events
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:
textControlLoaded: the editor is ready, and your code can use the JavaScript API.documentLoaded: the document that the view passed to the editor has been loaded.ribbonTabLoaded: once for each tab of the ribbon.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
| Event | Raised when | Handler receives |
|---|---|---|
textControlLoaded | The editor has been initialized and can be used from code | None |
documentLoaded | A document has been loaded | DocumentLoadedEventArgs |
ribbonTabLoaded | A ribbon tab has been loaded | RibbonTabLoadedEventArgs |
ribbonTabsLoaded | The ribbon and its texts from the server have been loaded completely | None |
ribbonTabIndexChanged | Another ribbon tab has been selected | RibbonTabIndexChangedEventArgs |
contentsReset | The whole content has been deleted and all attributes reset | None |
Document, Formatting and Input Position
| Event | Raised when | Handler receives |
|---|---|---|
changed | The content of the document has changed | None |
textControlChanged | Obsolete; use changed | — |
documentSizeChanged | The size of the document has changed | Size |
charFormatChanged | The character formatting of the selection or the input position has changed | None |
paragraphFormatChanged | The formatting of the selected paragraphs has changed | None |
pageFormatChanged | The page format has changed | None |
inputPositionChanged | The input position has changed | InputPositionChangedEventArgs |
inputParagraphChanged | The input position has moved to another paragraph | None |
mainTextActivated | The main text has received the input position from a header, footer or text frame | None |
headerFooterActivated, headerFooterDeactivated | A header or footer has received or lost the input position | HeaderFooterEventArgs |
textFrameActivated, textFrameDeactivated | A text frame has received or lost the input position | TextFrameEventArgs |
focus, blur | The editor has received or lost the focus | None |
zoomFactorChanged | The zoom factor has changed | ZoomFactorChangedEventArgs |
textViewLocationChanged | The visible part of the document has moved | TextViewLocationChangedEventArgs |
contextMenuOpening | A context menu is about to open; the handler can change its items | ContextMenuEventArgs |
Clipboard, Pasting and Dropping
| Event | Raised when | Handler receives |
|---|---|---|
clipboardModeChanged | The clipboard mode has changed | ClipboardModeChangedEventArgs |
clipboardDataTransferStart | A transfer of clipboard data starts | ClipboardTransferStartEventArgs |
clipboardDataTransferProgress | A packet of clipboard data has been transferred | ClipboardTransferProgressEventArgs |
clipboardDataTransferComplete | The transfer of clipboard data has completed | ClipboardTransferCompleteEventArgs |
clipboardDataTransferAborted | A transfer of clipboard data has been aborted | ClipboardTransferAbortedEventArgs |
textPasted | RTF, HTML or plain text is pasted with Ctrl+V | TextPastedEventArgs |
textDropped | RTF, HTML or plain text is dropped onto the editor | TextDroppedEventArgs |
fileDropped | A file is dropped onto the editor | FileDroppedEventArgs |
The argument objects of textPasted, textDropped and fileDropped have a cancel property.
Images, Frames, Tables and Shapes
| Event | Raised when | Handler receives |
|---|---|---|
frameSelected, frameDeselected, frameMoved, frameSized | A frame (image, text frame, chart, barcode or drawing) has been selected, deselected, moved or sized | FrameEventArgs |
imageCreated, imageDeleted, imageSelected, imageDeselected | An image has been created, deleted, selected or deselected | ImageEventArgs |
textFrameCreated, textFrameDeleted, textFrameSelected, textFrameDeselected | A text frame has been created, deleted, selected or deselected | TextFrameEventArgs |
chartCreated, chartDeleted, chartSelected, chartDeselected | A chart has been created, deleted, selected or deselected | ChartEventArgs |
barcodeCreated, barcodeDeleted, barcodeSelected, barcodeDeselected | A barcode has been created, deleted, selected or deselected | BarcodeEventArgs |
drawingCreated, drawingDeleted, drawingSelected, drawingDeselected, drawingActivated, drawingDeactivated | A drawing has been created, deleted, selected, deselected, activated or deactivated | DrawingEventArgs |
tableCreated | A table without an ID has been created by pasting or by loading a document | TableEventArgs |
tableDeleted | A table has been deleted | TableEventArgs |
tableOfContentsCreated, tableOfContentsDeleted | A table of contents has been created or deleted | TableOfContentsEventArgs |
tableOfContentsEntered, tableOfContentsLeft | The input position has moved into or out of a table of contents | TableOfContentsEventArgs |
Fields, Links and Regions
| Event | Raised when | Handler receives |
|---|---|---|
textFieldCreated, textFieldDeleted | A text field has been created or deleted | TextFieldEventArgs |
textFieldClicked, textFieldEntered, textFieldLeft | The user has clicked into a text field, or the input position has entered or left one | TextFieldEventArgs |
formFieldCheckChanged | A check box has been checked or cleared | CheckFormFieldEventArgs |
formFieldDateChanged | The date of a date form field has changed | DateFormFieldEventArgs |
formFieldSelectionChanged | Another item of a selection form field has been selected | SelectionFormFieldEventArgs |
formFieldTextChanged | The text of a text form field has changed | TextFormFieldEventArgs |
removeCombobox | The drop-down list of a selection form field has to be removed | None |
hypertextLinkClicked | A hypertext link has been clicked | HypertextLinkEventArgs |
documentLinkClicked | A link to a target in the document has been clicked | DocumentLinkEventArgs |
subTextPartCreated, subTextPartDeleted | A subtext part has been created or deleted | SubTextPartEventArgs |
subTextPartClicked, subTextPartDoubleClicked, subTextPartEntered, subTextPartLeft | The user has clicked or double-clicked into a subtext part, or the input position has entered or left one | SubTextPartEventArgs |
editableRegionCreated, editableRegionDeleted | An editable region has been created or deleted | EditableRegionEventArgs |
editableRegionEntered, editableRegionLeft | The input position has moved into or out of an editable region | EditableRegionEventArgs |
Track Changes and Comments
| Event | Raised when | Handler receives |
|---|---|---|
trackedChangeCreated, trackedChangeDeleted | A tracked change has been created or deleted | TrackedChangeEventArgs |
trackedChangeChanged | The text of a tracked change has changed | TrackedChangeEventArgs |
trackedChangeStateChanged | A tracked change has become active or inactive | TrackedChangeEventArgs |
cannotTrackChange | A change can't be recorded as a tracked change | A default message as a string |
commentCreated, commentDeleted | A comment has been created or deleted | CommentEventArgs |
commentChanged | The text of a comment has changed | CommentEventArgs |
commentStateChanged | A comment has become active or inactive | CommentEventArgs |
commentedTextEntered, commentedTextLeft | The input position has moved into or out of commented text | CommentEventArgs |
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
| Event | Raised when | Handler receives |
|---|---|---|
footnoteCreated, footnoteDeleted | A footnote has been created or deleted | FootnoteEventArgs |
footnoteReferenceMarkEntered, footnoteReferenceMarkLeft | The input position has moved to or away from a footnote reference mark | FootnoteEventArgs |
footnoteSectionActivated, footnoteSectionDeactivated | The footnote section of a page has received or lost the input position | None |
signatureFieldCreated, signatureFieldDeleted, signatureFieldSelected, signatureFieldDeselected | A signature field has been created, deleted, selected or deselected | SignatureFieldEventArgs |
Proofing
| Event | Raised when | Handler receives |
|---|---|---|
spellCheckText | Text has changed and its spelling needs to be checked | SpellCheckTextEventArgs |
hyphenateWord | A word doesn't fit into the line and needs to be hyphenated | HyphenateWordEventArgs |
Connection and Errors
| Event | Raised when | Handler receives |
|---|---|---|
webSocketClosed | The WebSocket connection to the server has been closed | WebSocketClosedEventArgs |
reconnectionFailed | The editor couldn't reconnect to the server | ReconnectionFailedEventArgs |
unhandledError | An error is about to be thrown | ErrorArgument |
Architecture explains what happens when the connection is lost and how the editor reconnects.