How to add text to the body of a plain element

I need to have custom text on the user task box once I drag and drop it to the modeller. In the path Text.js file at located in custom-elements example in custom-elements\node_modules\diagram-js\lib\util, we have the following text

// FF regression: ensure text is shown during rendering
// by attaching it directly to the body

Is this somewhere we need to tweak the code in order to add the custom text on drag and drop without user writing it on double click of the element


Text.js is not a good place to add this functionality since you have to change things in the source code of diagram-js. A better approach would be to extend bpmn-js using the eventBus. You could set predefined text like this:

is = require('bpmn-s/lib/util/ModelUtil').is,
eventBus.postExecute([ 'shape.create' ], function(e) {

  var element = e.context.shape;

  if (is(element, 'bpmn:Task')) {
    // when the shape is a task, set custom text = 'custom text';
1 Like

Thank you. This worked !!