# How to edit a BUTTON Node without triggering it

**URL:** https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001
**Category:** Dashboard
**Created:** [28 January 2024 19:15 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001 "2024-01-28T19:15:57Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [28 January 2024 19:15 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/1 "2024-01-28T19:15:57Z")

</div>

Hi all,  
is there a way to edit a BUTTON Node (from the generic Dashboard) ?  
I would like toggle it between ON and OFF and red color / green color if pressed.

But if I create an output from the button to a function node, adapting all settings and use the function output as input for the button, it will be triggered again ... in an endless loop, right ?

And is there a way to set the Button.Caption and Button.Color ?

BR  
Gawan

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 January 2024 19:43 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/2 "2024-01-28T19:43:14Z")

</div>

A button does not have an on/off state, it sends a value when pushed.  
There are many topics on this forum, here is one such [How to set up a toggle button?](https://discourse.nodered.org/t/how-to-set-up-a-toggle-button/80132/)

here are many from [Search results for 'toggle button' - Node-RED Forum](https://discourse.nodered.org/search?expanded=true&q=toggle%20button)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 January 2024 21:36 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/3 "2024-01-28T21:36:42Z")

</div>

> [@Gawan](#):
>
> use the function output as input for the button, it will be triggered again ... in an endless loop, right ?

Don't select `If msg arrives on input, emulate a button click:`  
Then it should not send a message when you send one in.

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [30 January 2024 16:32 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/4 "2024-01-30T16:32:07Z")

</div>

thanks collin, this works well

but unfortunately the button does not react on my inputs from the function node:

```auto
[{"id":"54ba0d4afac08d15","type":"ui_button","z":"a64b091a.a1bf2","name":"","group":"1495fa22.b16436","order":2,"width":1,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"1","payloadType":"num","topic":"topic","topicType":"msg","x":630,"y":460,"wires":[["89046dec383772c6"]]},{"id":"89046dec383772c6","type":"function","z":"a64b091a.a1bf2","name":"function 1","func":"var x = 0;\nx = global.get(\"EPEX.Active\");\nif (x==0){\n x = 1;\n global.set(\"EPEX.Active\",1);\n msg.background = \"red\";\n return [msg,null];\n}\nelse if (x==1){\n x = 0;\n global.set(\"EPEX.Active\",0);\n msg.background = \"green\";\n return [null,msg];\n}\n\nreturn msg;","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":460,"wires":[["54ba0d4afac08d15"],["54ba0d4afac08d15"]]},{"id":"1495fa22.b16436","type":"ui_group","name":"Standard","tab":"f420fdaa.3226a8","order":1,"disp":true,"width":8,"collapse":false},{"id":"f420fdaa.3226a8","type":"ui_tab","name":"EPEX Strom","icon":"dashboard","order":12,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 January 2024 17:18 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/5 "2024-01-30T17:18:50Z")

</div>

You have a few things wrong.

Firstly you should be using `let` not `var` nowadays. Google if you want to know why. That is not the cause of your problem though.

Secondly you are not setting x to anything if you have not already written a value to the global variable. In that case x will be undefined so neither of your tests will pass and the function will just return the message it was passed in. Change the first two lines to  
`let x = global.get("EPEX.Active") || 0;`  
That will set it to 0 if it is undefined.

Thirdly change the line  
`else if (x==1){`  
to  
`else {`  
and remove the return at the end. Then, if x ever gets to an illegal value it will not cause a major malfunction.

Finally, as written in the help for the button node, if you want to pass in the background colour in msg.background then in the Background field you have to put `{{background}}`

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [30 January 2024 17:42 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/6 "2024-01-30T17:42:49Z")

</div>

You are absolutely right - the function node was in the middle of beeing developed 🙂  
With your help I finally managed to set the button parameters as needed ! 👍

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/dec9ec3bc13c721a71c5242e3239e8cefb173fe6.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25bce9c9a6d13f90acb6df267f496b8b41836c2d.png)

---

<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: [29 February 2024 17:43 UTC](https://discourse.nodered.org/t/how-to-edit-a-button-node-without-triggering-it/85001/7 "2024-02-29T17:43:02Z")

</div>

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