Hi!
I am using the Kendo-UI Diagram widget to display relationships between items, that cannot be changed directly. I.e. I do not want users to be able to modify the diagram on their own. Unfortunately, I was not able to completely prevent modification of the diagram via its options.
For instance, I have set editable.remove to false. This prevents removing items already present at the widget's creation time, but it does not prevent removing items added later via diagram.addShape().
There are also several keyboard shortcuts like Ctrl+C (copy), Ctrl+V (paste), Ctrl+X (cut) and Ctrl+D (duplicate) that I would like to turn off.
The only solution I have found so far is blocking the corresponding keyboard events and preventing their default behavior, but this seems more like a hack than a solution.
What do you suggest?
Hello Michael,
To make the Kendo UI Diagram fully read-only and prevent all modifications (including for dynamically added shapes and keyboard shortcuts), here are the recommended steps:
1. Use the editable: false Option
Setting editable: false on initialization disables editing for all shapes and connections, including removing, adding, and modifying items. This also applies to shapes added later using diagram.addShape()—those shapes will inherit the read-only configuration and cannot be removed or modified through the UI.
Example:
$("#kendoDiagram").kendoDiagram({
editable: false
});
2. Prevent Keyboard Shortcuts
While editable: false disables most editing actions, some keyboard shortcuts (like copy, paste, cut, and duplicate) may still be active. To fully prevent these, handle the keydown event and suppress the relevant shortcuts:
Example:
$("#kendoDiagram").on("keydown", function(e) {
// Block Ctrl+C, Ctrl+V, Ctrl+X, Ctrl+D
if (e.ctrlKey && ["c", "v", "x", "d"].includes(e.key.toLowerCase())) {
e.preventDefault();
}
});
3. Prevent Removal of Dynamically Added Shapes
If you notice that dynamically added shapes can still be removed, make sure you are adding them after the diagram is initialized with editable: false. If you are adding shapes and still see removal possible, you can handle the remove event and prevent deletion programmatically:
Example:
var diagram = $("#kendoDiagram").data("kendoDiagram");
diagram.bind("remove", function(e) {
e.preventDefault(); // Prevent removing shapes/connections
});
Regards,
Nikolay
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.