How to copy inspector edit text value inside element box in jointJS - Rappid

738 views Asked by At

I want when writing something on the inspector displayName edit text to pass it to the inbox name of every element.enter image description here

My javascript code is the following:

  var count = 0;
//Code to edit element inboxName with value given from displayName field
                cell.on('change:wi_displayName', function(cell, change, opt) {

                    if(count == 0){
                    //Do nothing the 1st time
                    }
                    else {
                        var inboxName = cell.get('wi_displayName');
                        cell.set( cell.attr('text/text'), inboxName);

                    }
                    count++;

                })
//End of code to edit element inboxName with value given from displayName field

but the problem is in the final line:

cell.set( cell.attr('text/text'), inboxName);

How should I set the value?

My stencil json for this element is :

new joint.shapes.basic.Circle({
            size: { width: 5, height: 3 },
            attrs: {
                circle: { width: 50, height: 30, fill: '#000000' },
                text: { text: 'START', fill: '#ffffff', 'font-size': 10, stroke: '#000000', 'stroke-width': 0 }
            }
        })

Thank you

1

There are 1 answers

1
dave On BEST ANSWER

You can set the text attribute on your basic.Circle element with cell.attr('text/text', inboxName). The attr() method takes a path as the first argument which is the path to the attribute in your attrs object. Note that cell.attr('text/text', 'MY VALUE') is equivalent to cell.prop('attrs/text/text', 'MY VALUE').

cell.set() can only be used to set top level properties, so you would have to do cell.set('attrs', { text: { text: 'MY VALUE' } }) but that would override other attributes (like circle in your case).