Articles in this section
Category / Section

How to limit the text length of a node or connector annotation in JavaScript Diagram?

2 mins read

To limit the text length of node or connector annotations in Syncfusion®
Javascript Diagram, follow these steps:

KeyUp Event:

• Handle the KeyUp event, which is triggered when editing the text of a node or connector annotation.
• In this event, define a variable maxLength to specify the maximum number of characters allowed for the annotation.

Length Validation:

• Compare the length of the entered text with the maxLength value.
• If the text length exceeds the maxLength, truncate the text using the slice method in JavaScript.
• Update the content property of the annotation by assigning the truncated text to args.label.content.
• Finally, call the endEdit() method to conclude the editing mode of the node or connector annotation.

//Initializes diagram control
diagram = new ej.diagrams.Diagram({
 width: '100%',
 height: 580,
 connectors: connectors,
 keyUp: keyUp,
 textEdit: textEdit,
});
diagram.appendTo('#diagram');

function keyUp(args) {
 let maxlength = 20;
 if (args.text.length > maxlength) {
   args.text = args.text.slice(0, maxlength);
   args.label.content = args.text;
   diagram.endEdit();
 }
}

function textEdit(args) {
 args.cancel = true;
}

Sample
Conclusion
​I hope you enjoyed learning about how to limit the text length of a node or connector annotation.
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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied