Calling a function on double click on node

Is there a way to call a function when double clicking the node. I need to get some data from an API so I can display in the editor so the user can select it.


Yes, oneditprepare is run when you open a node's Editor panel. Just be aware that it is also run when you load the editor. That is generally what you want to happen but occasionally it will catch you out (or it does me anyway).

Lots of nodes do this. Possibly the serial node is one of the simplest. uibuilder does it too.

I have this, but I never see any data on the oneditprepare section.

module.exports = function(RED) {
    function CreateNetwork(config) {
        RED.nodes.createNode(this, config);
        const node = this;

        this.on('oneditprepare', function() {
         my logic....

    RED.nodes.registerType('create-network', CreateNetwork);

oneditprepare is part of the node's configuration in the editor. It is defined in the html file - HTML File : Node-RED

It gets called in the editor when a user double clicks on a node. Its purpose is to do any custom work needed to prepare the edit dialog.

It could, for your scenario, make an http request back to the runtime to a route your nodes js file defines to retrieve whatever data is needed.

There is an explanation of how the Serial node does something similar here: javascript - Send data on configuration - Stack Overflow

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.