How to Disable Copy Action on Specific Node in JavaScript Diagram?
In Syncfusion® JavaScript Diagram, there is no built-in option to prevent copying a specific node using the default Ctrl+C behavior. However, you can customize the behavior by leveraging the commandManager functionality. This customization enables you to conditionally execute commands, such as allowing or restricting the copy operation based on the properties of the node.
Below is a code sample that demonstrates how to implement the above functionality:
- A custom command named customCopy is defined in the commandManager. It utilizes the canExecute function to check the Copy flag before allowing the copy operation.
- Each node uses the addInfo property to store a Copy flag. This flag determines whether the node can be copied.
//initialize the diagram control
var diagram = new ej.diagrams.Diagram({
width: '100%',
height: '500px',
commandManager: {
commands: [
{
name: 'customCopy',
parameter: 'node',
// efine whether the command can be executed at the current moment
canExecute: function () {
if (diagram.selectedItems.nodes.length > 0 &&
diagram.selectedItems.nodes[0].addInfo.Copy) {
return true;
}
return false;
},
// execute commands if canExecute returns true
execute: function () {
//Logic to clone the selected element
console.log('copy triggered');
diagram.copy();
},
//The gesture property specifies that this command should be triggered using Ctrl+C.
gesture: {
key: ej.diagrams.Keys.C,
keyModifiers: ej.diagrams.KeyModifiers.Control,
},
},
],
},
});
diagram.appendTo('#diagram');
Sample: Click Here
Conclusion
I hope you enjoyed on how to disable the copy action on specific node in JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page.
If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!