Change read/write attribute of a property accross different nodes

Hi,
I am working with a Flowchart and an Inspector.

In the init() function, I define the set of all the properties that a node might use:

function init() {
...
properties = {
        "text": {readOnly: true, show: Inspector.showIfPresent},
        "no_channels": {readOnly: false, show: Inspector.showIfPresent},
        ...
}

then I define my Inspector:

var inspector = new Inspector('myInspectorDiv', myDiagram, {
        multipleSelection: true,
        showSize: 10,
        showAllProperties: false,
        // includesOwnProperties: false,
        properties: properties
    });

and finally I add my nodes to the Palette:

var myPalette = $(go.Palette, "myPaletteDiv");
myPalette.nodeTemplateMap = myDiagram.nodeTemplateMap;
myPalette.model.nodeDataArray = [
    {category: "X", text: "X", no_channels:0, ... },
    {category: "Y", text: "Y", no_channels:0, ... },
...
];

Is there a way to make no_channels read-only in node X but editable in node Y?
Thanks !

Yes, you can specify readOnly as a function taking the part as the first argument:

...
properties = {
  "text": { readOnly: true, show: Inspector.showIfPresent },
  "no_channels": {
    readOnly: function(p) { return p.data.text === "X";  },
    show: Inspector.showIfPresent
  },
  ...
}
1 Like