# Calling a function on double click on node

**URL:** https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069
**Category:** Developing Nodes
**Created:** [8 June 2023 20:15 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069 "2023-06-08T20:15:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![enniob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/enniob/32/80482_2.png) [@enniob](https://discourse.nodered.org/u/enniob)
#### Post date: [8 June 2023 20:15 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069/1 "2023-06-08T20:15:37Z")

</div>

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.

Thanks,  
Ennio

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 June 2023 20:29 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069/2 "2023-06-08T20:29:06Z")

</div>

> [@enniob](#):
>
> Is there a way to call a function when double clicking the node.

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).

> [@enniob](#):
>
> I need to get some data from an API so I can display in the editor so the user can select it.

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

---

<div class="post-metadata">

### Author: ![enniob](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/enniob/32/80482_2.png) [@enniob](https://discourse.nodered.org/u/enniob)
#### Post date: [8 June 2023 20:42 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069/3 "2023-06-08T20:42:22Z")

</div>

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

```auto
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);
}

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [8 June 2023 21:25 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069/4 "2023-06-08T21:25:15Z")

</div>

`oneditprepare` is part of the node's configuration in the editor. It is defined in the html file - [HTML File : Node-RED](https://nodered.org/docs/creating-nodes/node-html)

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](https://stackoverflow.com/questions/41567175/send-data-on-configuration/41567832#41567832)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [22 June 2023 21:25 UTC](https://discourse.nodered.org/t/calling-a-function-on-double-click-on-node/79069/5 "2023-06-22T21:25:25Z")

</div>

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