# Saving button background color while disabled

**URL:** <https://discourse.nodered.org/t/saving-button-background-color-while-disabled/23372>\
**Category:** Dashboard\
**Created:** [20 March 2020 20:58 UTC](https://discourse.nodered.org/t/saving-button-background-color-while-disabled/23372 "2020-03-20T20:58:41Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![kocherjj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kocherjj/32/20578_2.png) [@kocherjj](https://discourse.nodered.org/u/kocherjj)\
**Post date:** [20 March 2020 21:40 UTC](https://discourse.nodered.org/t/saving-button-background-color-while-disabled/23372/4 "2020-03-20T21:40:43Z")

</div>

Thanks to both of you for your replies!

I eventually found this post:

> [@Can I have a delay / sleep inside Function node](https://discourse.nodered.org/t/can-i-have-a-delay-sleep-inside-function-node/3101):
>
> I'm pretty certain that the answer is going to be no but can I do something in a function node - wait a bit - do something else? or do I need to have two function nodes with a Delay node in-between them?

That got me experimenting along new lines and I came up with this solution, which basically follows what gerry said. I am still new to this whole writing code thing, which is why I love Node-Red because I can use nodes for the bulk of the logic and learn some code in a function node on a very specific task.

It took a bit to figure out how to use node.send with multiple outputs, and then I clearly don't understand exactly what the timeout function is doing because it seems to be backwards compared to how I would think it would go but this code is working for me now.

Thanks for the tips on writing better code!

I still feel like an isolated enable command shouldn't reset the button state, it should just enable it. That feels like a bug to me but I'm not complaining. I'm grateful to have access to Node-Red at all!

```auto
[{"id":"dab9bb38.6245e8","type":"ui_button","z":"f1d06a71.51424","name":"State 2","group":"dd64112c.15ad78","order":22,"width":0,"height":0,"passthru":false,"label":"State 2","tooltip":"","color":"{{msg.color}}","bgcolor":"{{msg.background}}","icon":"","payload":"2","payloadType":"str","topic":"","x":300,"y":180,"wires":[["c8ca7726.51e9"]]},{"id":"6ff77c47.0a405c","type":"ui_button","z":"f1d06a71.51424","name":"State 1","group":"dd64112c.15ad78","order":21,"width":0,"height":0,"passthru":false,"label":"State 1","tooltip":"","color":"{{msg.color}}","bgcolor":"{{msg.background}}","icon":"","payload":"1","payloadType":"str","topic":"","x":300,"y":140,"wires":[["c8ca7726.51e9"]]},{"id":"c8ca7726.51e9","type":"function","z":"f1d06a71.51424","name":"Button State","func":"if (msg.payload == \"1\"){\n setTimeout(function(){\n msg1 = {enabled:true, background:\"#0094CE\", color:\"white\"};\n msg2 = {enabled:true, background:\"#036288\", color:\"grey\"};\n node.send([msg1, msg2]);\n }, 5000);\n msg1 = {enabled:false, background:\"#0094CE\", color:\"white\"};\n msg2 = {enabled:false, background:\"#036288\", color:\"grey\"};\n node.send([msg1, msg2]);\n}\nelse if (msg.payload == \"2\"){\n setTimeout(function(){\n msg1 = {enabled:true, background:\"#036288\", color:\"grey\"};\n msg2 = {enabled:true, background:\"#0094CE\", color:\"white\"};\n node.send([msg1, msg2]);\n }, 5000);\n msg1 = {enabled:false, background:\"#036288\", color:\"grey\"};\n msg2 = {enabled:false, background:\"#0094CE\", color:\"white\"};\n node.send([msg1, msg2]);\n}","outputs":2,"noerr":0,"x":290,"y":240,"wires":[["6ff77c47.0a405c"],["dab9bb38.6245e8"]]},{"id":"dd64112c.15ad78","type":"ui_group","z":"","name":"Test","tab":"6d2ffe37.0d7c8","disp":true,"width":"6","collapse":false},{"id":"6d2ffe37.0d7c8","type":"ui_tab","z":"","name":"Test","icon":"dashboard","disabled":false,"hidden":false}]

```

---

_[View the full topic](https://discourse.nodered.org/t/saving-button-background-color-while-disabled/23372)._
