Products Technologies Demo Docs Blog Support Company

This blog post contains outdated information.

The cited code snippets may be workarounds, and be part of the official API in the meantime.

TextControl.Web: Inserting Merge Fields Using Javascript

The hidden JavaScript API in TextControl.Web X12 exposes internal editor commands through the enableCommands function. Calling TXTextControl.sendCommand with the InsertItem command and FieldAdapter item type inserts merge fields at the current input position in the editor.

TextControl.Web: Inserting Merge Fields Using Javascript

In a recent post, we already introduced the hidden Javascript interface that is available in version X12. This interface gives you access to the majority of internal Javascript calls that are used in TextControl.Web. This interface is hidden by default, because it is still in beta and undocumented.

In order to enable the hidden interface, the function enableCommands() must be called.

TXTextControl.enableCommands();

The following code inserts a merge field with a specific name into the currently active TextPart (Header, Footer, MainText or TextFrame).

function insertField(name) {
    var mergeField = {
        Name: name,
        Text: "«" + name + "»"
    };
    TXTextControl.sendCommand(
        TXTextControl.Command.InsertItem,
        TXTextControl.ItemType.FieldAdapter,
        TXTextControl.FieldType.MergeField,
        0, mergeField);
}

The following call inserts a MergeField with the name fieldname at the current input position:

TXTextControl.enableCommands();
insertField(\'fieldname\');

Stay tuned to learn more about the hidden JS interface.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


HTML5Sample

TextControl.Web: Determine when a Document Has Been Completely Loaded

Web.TextControl fires a waitDialogMessageReceived event during document loading. The event detail includes a show property that is true when loading starts and false when loading completes. This…


HTML5Sample

TextControl.Web: Adding Custom Ribbon Tabs

Web.TextControl supports adding custom ribbon tabs through JavaScript DOM manipulation. After the ribbonTabsLoaded event fires, new tab headers and content panels with buttons are injected into…


ASP.NETGitHubHTML5

Building a Touch-enabled Button Bar with Javascript

This sample builds a custom touch-friendly button bar for Web.TextControl using its JavaScript API. HTML input elements styled with CSS replace the desktop ribbon bar. Click events call…


ASP.NET CoreHTML5Middleware

Securing WebSocket Connections in ASP.NET Core using Sec WebSocket Protocol…

This article explores how to secure WebSocket connections in ASP.NET Core applications by utilizing the Sec-WebSocket-Protocol header for authentication and authorization purposes.

Share on this blog post on: