# Button node bug report. (Look at bottom)

**URL:** <https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741>\
**Category:** General\
**Created:** [28 February 2021 07:04 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741 "2021-02-28T07:04:48Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 February 2021 09:31 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/21 "2021-02-28T09:31:46Z")

</div>

There isn't a bug that I can see. The node just has to be used correctly.

(And I don't know how to. There is no "bug report" option in the bull downs.)

---

<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 February 2021 09:48 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/22 "2021-02-28T09:48:29Z")

</div>

> [@Trying\_to\_learn](#):
>
> There isn't a bug that I can see.

Try the test case that I posted, where I have the send topic set to an empty string, which is what you had in the original flow you posted. Then it should always send an empty topic, but it doesn't, it behaves as if `msg.topic` is specified. So your original problem was due to this bug. You can submitting a bug against the dashboard just like any other node at [Issues · node-red/node-red-dashboard · GitHub](https://github.com/node-red/node-red-dashboard/issues)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 February 2021 09:51 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/23 "2021-02-28T09:51:22Z")

</div>

The new `button` node has a selector to _select_ what is the topic.

As it is set to `msg.topic` and it receives the **setup** message - from the `inject` node it gets that topic.

Subsequent pressing of the button it keeps that topic.

Is that a bug? I'm not qualified to say if it is or not.  
(Remember: I can't read)

So that I had the node set to use `msg.topic` (the default) and if I change it to _something\_else_ as a `string` then it works.

No bug.

---

<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 February 2021 10:03 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/24 "2021-02-28T10:03:11Z")

</div>

> [@Trying\_to\_learn](#):
>
> So that I had the node set to use `msg.topic`

Look in your original flow, that is _not_ how you have configured the button.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b801d5b496498476b0e98600e660eb0a5f4eafe6.png)

So it should have sent the topic as an empty string, but it wasn't, it was sending it as if you had `msg.topic` set there. That is the bug.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 February 2021 10:10 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/25 "2021-02-28T10:10:08Z")

</div>

You haven't got the latest `button`.

That is the OLD one.

The new one is different.

![Screenshot from 2021-02-28 21-07-33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5308ea4fd103c661cd1472cf23ce5b9ace171dd3.png)

That is the default.

To _fix_ the problem I (now) have is I just change it so the `Topic` is set to `string` and something else written there.

The OLD ones work fine.

When I updated to the new ones, _the wheels fell off the wagon_ - because I didn't change the topic's settings.

Why do you see that as a bug?

---

<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 February 2021 10:28 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/26 "2021-02-28T10:28:33Z")

</div>

Look at the original flow you posted, that is configured as in the image I posted, in fact the image I posted is taken from your original flow. The Button is _not_ at the default setting.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 February 2021 10:39 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/27 "2021-02-28T10:39:43Z")

</div>

This is the one which is the OLD way. I **used to work**. It doesn't any more with the new `button` node.

```auto
[{"id":"5dcb15fb.24d17c","type":"inject","z":"39ea4ac5.b46c1e","name":"Inject","repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"str","x":420,"y":860,"wires":[["6272e4a0.8faa44"]]},{"id":"6272e4a0.8faa44","type":"function","z":"39ea4ac5.b46c1e","name":"Setup","func":"msg = {\n \"topic\":\"SETUP\",\n \"disabledColour\":\"brown\",\n \"colourA\": \"lime\",\n \"colourB\": \"green\",\n \"txtA\": \"Log\",\n \"txtB\": \"Log Stop\",\n \"txtclrA\": \"black\",\n \"txtclrB\": \"black\",\n \"payloadA\": \"GO\",\n \"payloadB\": \"STOP\",\n \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":900,"wires":[["93f710a2.69e118"]]},{"id":"a999cdd7.d7fdc","type":"ui_button","z":"39ea4ac5.b46c1e","name":"Error Logging","group":"d057989d.1f3368","order":3,"width":"2","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"","x":630,"y":860,"wires":[["93f710a2.69e118","763a7526.22a8f4"]]},{"id":"93f710a2.69e118","type":"function","z":"39ea4ac5.b46c1e","name":"Push Button","func":"// working\nvar state = context.get(\"STATE\")||0;\nvar enabled = context.get(\"ENABLED\")||0;\n\n// Look for a message with topic set to SETUP to set values.\nif (msg.topic == \"SETUP\") //Do this if the message is NOT \"X\"\n{\n //\n // Background colours first.\n //\n context.set(\"ABGC\", msg.colourA);\n context.set(\"BBGC\", msg.colourB);\n //\n // Disabled button background colour.\n //\n context.set(\"DISABLEDCLR\",msg.disabledColour);\n //\n // Now do text.\n //\n context.set(\"Atxt\", msg.txtA);\n context.set(\"Btxt\", msg.txtB);\n //\n // Font colours.\n //\n context.set(\"AFC\",msg.txtclrA);\n context.set(\"BFC\",msg.txtclrB);\n //\n // Payloads.\n //\n context.set(\"PayloadA\", msg.payloadA);\n context.set(\"PayloadB\", msg.payloadB);\n //\n // Topic.\n //\n if (msg.topicSET !== null)\n {\n context.set(\"Topic\",msg.topicSET);\n } else\n {\n context.set(\"Topic\",\"~\");\n }\n msg.txt = msg.txtA;\n msg.colour = msg.disabledColour;\n msg.fontclr = msg.txtclrA;\n return msg;\n}\n\n// Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n //node.warn(\"X detected\");\n // Insert here code to enable other stuff.\n// if (context.get(\"ENABLED\") === 0)\n if (enabled === 0)\n {\n //\n // Old code.\n //\n //node.warn(\"Setting enable\");\n// context.set(\"ENABLED\",1);\n// msg.txt = context.get(\"Atxt\");\n// msg.colour = context.get(\"ABGC\");\n// msg.fontclr = context.get(\"AFC\");\n\n // New code.\n \n //node.warn(\"State = \" + state);\n\n if (state === 0)\n {\n //\n // Set things for state 0\n //\n //node.warn(\"State 0 detected\");\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"ABGC\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n }\n else if (state === 1)\n {\n //\n // Set things for state 1\n //\n //node.warn(\"State 1 detected\");\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"BBGC\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n context.set(\"ENABLED\",1);\n return msg;\n }\n\n// if (context.get(\"ENABLED\") === 1)\n state = (state + 1)% 2;\n //node.warn(state);\n context.set(\"STATE\",state);\n if (enabled === 1)\n {\n if (state === 0)\n {\n // Condition A\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"ABGC\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n } else\n if (state === 1)\n {\n // Condition B\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"BBGC\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n }\n \n if (context.get(\"Topic\") == \"~\")\n {\n msg.topic = \"\";\n } else\n {\n msg.topic = context.get(\"Topic\");\n }\n return msg;\n}\nif (msg.payload == \"Z\")\n{\n //\n ////node.warn(\"Timed out\");\n //\n context.set(\"ENABLED\",0);\n if (state === 0)\n {\n //\n // Set things for state 1\n //\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"DISABLEDCLR\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n }\n else if (state === 1)\n {\n //\n // Set things for state 2\n //\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"DISABLEDCLR\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":900,"wires":[["a999cdd7.d7fdc","1ddaae04.be6602"]]},{"id":"763a7526.22a8f4","type":"trigger","z":"39ea4ac5.b46c1e","name":"","op1":"","op2":"Z","op1type":"nul","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","outputs":1,"x":610,"y":940,"wires":[["93f710a2.69e118"]]},{"id":"d057989d.1f3368","type":"ui_group","name":"Errors","tab":"41ad2f9a.ed0df","order":2,"disp":true,"width":"6","collapse":false},{"id":"41ad2f9a.ed0df","type":"ui_tab","name":"Logging","icon":"list","order":5,"disabled":false,"hidden":false}]

```

It is the default setting for the button.

This is the **modified** flow and the node has been changed.

```auto
[{"id":"c5ccf203.8fff9","type":"inject","z":"39ea4ac5.b46c1e","name":"Inject","repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"str","x":290,"y":440,"wires":[["a95c95ac.a0ab6"]]},{"id":"a95c95ac.a0ab6","type":"function","z":"39ea4ac5.b46c1e","name":"Setup","func":"msg = {\n \"topic\":\"SETUP\",\n \"disabledColour\":\"brown\",\n \"colourA\": \"lime\",\n \"colourB\": \"green\",\n \"txtA\": \"Display\",\n \"txtB\": \"Display Stop\",\n \"txtclrA\": \"black\",\n \"txtclrB\": \"black\",\n \"payloadA\": \"GO\",\n \"payloadB\": \"STOP\",\n \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":480,"wires":[["e0d476a7.3e5e7"]]},{"id":"1d77a37e.a76b95","type":"ui_button","z":"39ea4ac5.b46c1e","name":"Commands RX List","group":"1baf0833.3ae918","order":1,"width":"2","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"blah","topicType":"str","x":510,"y":440,"wires":[["e0d476a7.3e5e7","aa338cfc.ca1fd"]]},{"id":"e0d476a7.3e5e7","type":"function","z":"39ea4ac5.b46c1e","name":"Push Button","func":"var state = context.get(\"STATE\")||0;\nvar enabled = context.get(\"ENABLED\")||0;\n\n// Look for a message with topic set to SETUP to set values.\nif (msg.topic == \"SETUP\") //Do this if the message is NOT \"X\"\n{\n //\n // Background colours first.\n //\n context.set(\"ABGC\", msg.colourA);\n context.set(\"BBGC\", msg.colourB);\n //\n // Disabled button background colour.\n //\n context.set(\"DISABLEDCLR\",msg.disabledColour);\n //\n // Now do text.\n //\n context.set(\"Atxt\", msg.txtA);\n context.set(\"Btxt\", msg.txtB);\n //\n // Font colours.\n //\n context.set(\"AFC\",msg.txtclrA);\n context.set(\"BFC\",msg.txtclrB);\n //\n // Payloads.\n //\n context.set(\"PayloadA\", msg.payloadA);\n context.set(\"PayloadB\", msg.payloadB);\n //\n // Topic.\n //\n if (msg.topicSET !== null)\n {\n context.set(\"Topic\",msg.topicSET);\n } else\n {\n context.set(\"Topic\",\"~\");\n }\n msg.txt = msg.txtA;\n msg.colour = msg.disabledColour;\n msg.fontclr = msg.txtclrA;\n return msg;\n}\n\n// Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n //node.warn(\"X detected\");\n // Insert here code to enable other stuff.\n// if (context.get(\"ENABLED\") === 0)\n if (enabled === 0)\n {\n //\n // Old code.\n //\n //node.warn(\"Setting enable\");\n// context.set(\"ENABLED\",1);\n// msg.txt = context.get(\"Atxt\");\n// msg.colour = context.get(\"ABGC\");\n// msg.fontclr = context.get(\"AFC\");\n\n // New code.\n \n //node.warn(\"State = \" + state);\n\n if (state === 0)\n {\n //\n // Set things for state 0\n //\n //node.warn(\"State 0 detected\");\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"ABGC\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n }\n else if (state === 1)\n {\n //\n // Set things for state 1\n //\n //node.warn(\"State 1 detected\");\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"BBGC\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n context.set(\"ENABLED\",1);\n return msg;\n }\n\n// if (context.get(\"ENABLED\") === 1)\n state = (state + 1)% 2;\n //node.warn(state);\n context.set(\"STATE\",state);\n if (enabled === 1)\n {\n if (state === 0)\n {\n // Condition A\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"ABGC\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n } else\n if (state === 1)\n {\n // Condition B\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"BBGC\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n }\n \n if (context.get(\"Topic\") == \"~\")\n {\n msg.topic = \"\";\n } else\n {\n msg.topic = context.get(\"Topic\");\n }\n return msg;\n}\nif (msg.payload == \"Z\")\n{\n //\n ////node.warn(\"Timed out\");\n //\n context.set(\"ENABLED\",0);\n if (state === 0)\n {\n //\n // Set things for state 1\n //\n msg.payload = context.get(\"PayloadA\");\n msg.colour = context.get(\"DISABLEDCLR\");\n msg.txt = context.get(\"Atxt\");\n msg.fontclr = context.get(\"AFC\");\n }\n else if (state === 1)\n {\n //\n // Set things for state 2\n //\n msg.payload = context.get(\"PayloadB\");\n msg.colour = context.get(\"DISABLEDCLR\");\n msg.txt = context.get(\"Btxt\");\n msg.fontclr = context.get(\"BFC\");\n }\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":480,"wires":[["1d77a37e.a76b95","217a2e14.0dbb4a"]]},{"id":"aa338cfc.ca1fd","type":"trigger","z":"39ea4ac5.b46c1e","name":"","op1":"","op2":"Z","op1type":"nul","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","outputs":1,"x":480,"y":520,"wires":[["e0d476a7.3e5e7"]]},{"id":"1baf0833.3ae918","type":"ui_group","name":"Cmds Received","tab":"41ad2f9a.ed0df","order":1,"disp":true,"width":"6","collapse":false},{"id":"41ad2f9a.ed0df","type":"ui_tab","name":"Logging","icon":"list","order":5,"disabled":false,"hidden":false}]

```

I don't know if I am getting more and more stupid as this thread continues, or what.

> [@Colin](#):
>
> Why? All you have to do is (in your test case) change the send topic to an empty string and you have correctly shown that there is a bug in the button node.
> 
> Like this

That code has the same problem. You just added an extra node, to achieve what?

The TOPIC from the button being pressed is not correct - by the old way.  
The new way..... I don't know.  
Should it _Keep_ the previous topic and use it for ongoing messages?  
(You are asking the wrong person)

Honestly: I've seen my mistake. I've edited the nodes and made them send a different topic.  
_Problem_ solved.

All the buttons now are the new ones. Kinda makes the old one's _quirks_ irrelevant.

---

<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 February 2021 11:58 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/28 "2021-02-28T11:58:40Z")

</div>

Answer me two questions please.  
Question 1. In your original flow (as you have just re-posted) did you have the send topic configured to be an empty string.  
Clue  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/026f5ce0c9e83293e4ed458025629102871686fa.png)

Question 2. Did it send an empty string in the topic when you clicked it?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b430e630109d7d63a6e62b75535cbb9adfd39afc.png)

If the answer to question 1 is Yes and to question 2 is No then the button is not behaving as you have configured it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 February 2021 19:50 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/29 "2021-02-28T19:50:28Z")

</div>

The original flow had the `msg.topic` left as blank.

It used to work.

Updating it to the newer version this behaviour is different.

---

<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 February 2021 20:05 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/30 "2021-02-28T20:05:55Z")

</div>

Are you able to answer the questions?  
I am attempting to prove that there is a bug in the current version, which you have disputed.

---

<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:** [28 February 2021 20:14 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/31 "2021-02-28T20:14:21Z")

</div>

@Colin You've tried to make your point with @Trying_to_learn, but he isn't seeing it. At this point, please just raise an issue yourself.

---

<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:** [1 March 2021 09:49 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/32 "2021-03-01T09:49:13Z")

</div>

I think you are right. See [bug report](https://github.com/node-red/node-red-dashboard/issues/687).

Thanks to @Trying_to_learn for finding this bug, even though it appears that he will not accept that it is a bug, and that it is the cause of the problem that this post is about, which he worked around by providing a string in the configured topic rather than leaving it empty.

---

<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:** [15 March 2021 09:49 UTC](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741/33 "2021-03-15T09:49:52Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/button-node-bug-report-look-at-bottom/41741.md?page=1)
