2

Custom UI: Drag and Drop Merge Fields into the Document Editor

 1 year ago
source link: https://www.textcontrol.com/blog/2023/04/03/custom-ui-drag-and-drop-merge-fields-into-the-document-editor/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Drag and Drop Merge Fields into the Document Editor

For many applications, the out-of-the-box Reporting UI may be too complex and require too much training. It is helpful to tailor the UI to the user's level of expertise to enhance the user experience and streamline workflows.

Live Demo

Test this code live in the Drag and Drop Fields sample that is part of the Technical Demos.

Launch Demo

Drag and Drop

A very common technical support question is whether it is possible to drag and drop merge fields from a sidebar or tree view. The JavaScript API provides full access to the functionality, including adding merge fields, that allows you to implement such a sidebar.

Drag and drop merge fields

For this example, we will use the following simple data object:

In the Razor view code, a list is created based on the given data object:

Event Handler

When the page loads, the following JavaScript code adds the draggable attribute to the elements and attaches an event handler:

This results in the following HTML:

Transfer Data

The attached event handler drag sets the data transfer data for the drop event in the Text Control editor.

Input Position

While dragging over the editor, the input position is actively changed, so that the field can be added at the new input position when the drop event is fired.

The variable _txtViewLoc is updated in the textViewLocationChanged event to provide the scroll offset position to calculate the correct input position.

New Merge Field

When the field is finally dropped, a new merge field is created with the name of the data transfer data and is inserted at the current input position.

The complete JavaScript is listed below.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK