I have tried searching and looking through node-red function and switch nodes but cant pin down how I can have 1 or 2 outputs depending on a users choice in a drop-down
For example, suppose I had an option on my custom node...
Throw errors (default)
Send errors in msg.error
Send errors to separate output
When a user chooses "Send errors to separate output" I'd like the node to change from having 1 output to having 2 outputs.
What am I doing wrong? I always get the message "Cannot use in operator ...".
RED.nodes.registerType('sonosevents-notify', {
category: 'sonosevents',
defaults: {
confignode: {
value: '',
type: 'sonosevents-config'
},
outputs: 1
},
inputs: 0, // set the number of inputs - only 0 or 1
//outputs: 1, // set the number of outputs - 0 to n
color: '#AAAAAA',
label: function() {
return 'events';
},
paletteLabel: 'sonosevents'
});
Whilst you have added an outputs property to the defaults object, it isn't properly configured. You need to follow the same pattern used by the other properties in the defaults object:
This gets me almost but not quite where I want to go. I want my node to have one or two outputs, depending on the state of a checkbox. It seems like the variable associated with the checkbox is not available until I close the edit dialog, at which point it is too late to change the outputs property. The second time I close the dialog, the oneditsave code picks up the change. There must be something I can do, but my jQuery skills are severely limited. Any suggestions?
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...
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.