How can my custom node have dynamic number of outputs?

You should be able to set node.outputs in an on change event.

Supposing your check box is named node-input-check and "checked" means 2 outputs & unchecked means 1 output, this might be overkill but it covers all bases...

defaults: {
    name: { value: "" },
    check: { value: true },
    outputs: { value: 2 }
}

...

oneditprepare: function () {
    var node = this;
    node.outputs = $("#node-input-check").prop('checked') ? 2 : 1;
    $("#node-input-check").change(function() {
        node.outputs = this.checked ? 2 : 1;
    });            
},
oneditsave: function () {
    var node = this;
    node.outputs = $("#node-input-check").prop('checked') ? 2 : 1;
}

NOTES: I always try to ensure outputs and check default to matching state (e.g. if you default the check to checked then default outputs to 2) so that when you add a new node and defaults are applied, they match each other.

(untested)

3 Likes