Version X12 (22.0) implements a programmable Web.Selection object that allows server-side document manipulation. With the same release, we introduced some client-side Javascript events and methods.

But what you might not know is a hidden interface that can be enabled using the Javascript function enableCommands. This gives you access to the majority of internal Javascript calls that are used in TextControl.Web. This interface is hidden, because it is not finished yet and we might do changes on the interface. So, please be careful with this Javascript API. At the same time, we won't remove functionality - so, feel free to test this interface for your own purposes.

In this sample, the client-side Javascript events textFieldEntered and textFieldLeft are used to set the EditMode of TextControl.Web. In the beginning, the EditMode is set to ReadAndSelect and the text fields are editable:

<cc1:TextControl ID="TextControl1"
    runat="server"
    EditMode="ReadAndSelect"
    TextFieldsEditable="True"
    Dock="Window" />

The following Javascript code enables the hidden Javascript interface and attaches the two events to the HTML5-based editor:

TXTextControl.enableCommands();

TXTextControl.addEventListener("textFieldEntered", function (e) {
    TXTextControl.sendCommand(TXTextControl.Command.SetEditMode,
        TXTextControl.EditMode.Edit);
});

TXTextControl.addEventListener("textFieldLeft", function (e) {
    TXTextControl.sendCommand(TXTextControl.Command.SetEditMode,
        TXTextControl.EditMode.ReadAndSelect);
});

In the anonymous functions of the event listeners, sendCommand is used to set the EditMode. If the input position is inside a text field (textFieldEntered), the edit mode is set to Edit and vice versa in the textFieldLeft event.

The result of this event handling is that the document is protected except for text fields. Users can change the text of text fields or complete forms while the rest of the document is protected.

You can download the sample to test this on your own. At least a trial version of TX Text Control .NET Server for ASP.NET and Visual Studio 2012 is required.

Stay tuned to learn more about the hidden Javascript interface.