# How to combine text input node with button node

**URL:** <https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871>\
**Category:** Dashboard\
**Created:** [12 February 2019 11:18 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871 "2019-02-12T11:18:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dolfandringa](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@dolfandringa](https://discourse.nodered.org/u/dolfandringa)\
**Post date:** [12 February 2019 11:18 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/1 "2019-02-12T11:18:06Z")

</div>

How can I have a text input where the user enters a value (possibly with a preceding Inject to set the default value), and a button node, that when clicked, takes the value of the text input and sends it out.  
Just chaining a text input to a button node doesn't work as the button node will overwrite the msg.payload. I guess I am looking for a button that interrupts the flow until the button is pressed. So it doesn't change the msg object, it just waits with outputting whatever came in until the button is clicked.

---

<div class="post-metadata">

**Author:** ![Grizzly](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Grizzly](https://discourse.nodered.org/u/Grizzly)\
**Post date:** [17 April 2019 14:33 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/2 "2019-04-17T14:33:19Z")

</div>

Hello !

If the question is always open, you can do as above :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/eda60eb57778b2599469ee79b8574d56adfa7769.png)

and the associated flow:

[{"id":"4ec0caef.1d59ac","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"a444821b.ba15c8","type":"ui\_text\_input","z":"4ec0caef.1d59ac","name":"1","label":"1 : ","tooltip":"","group":"9b65de7c.212788","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"1","x":321,"y":161,"wires":[["61a8669.9179598"]]},{"id":"a73fc64c.d6551","type":"ui\_button","z":"4ec0caef.1d59ac","name":"","group":"9b65de7c.212788","order":1,"width":"3","height":"1","passthru":false,"label":"Save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"false","payloadType":"bool","topic":"","x":319,"y":218,"wires":[["61a8669.9179598"]]},{"id":"61a8669.9179598","type":"function","z":"4ec0caef.1d59ac","name":"analyze message","func":"\n\n// initialize variable as "" if it don't exist\nvar station1 = context.get('station1')||"";\n\nif (msg.topic==="1") {\n station1=msg.payload\n}\n\n// store the value back\ncontext.set('station1',station1);\n\n\nif (msg.payload===false) {\n msg.payload=context.get('station1');\n return msg;\n} \n\n \n","outputs":1,"noerr":0,"x":515.5,"y":218,"wires":[["f26ba179.aaa478"]]},{"id":"65c46ea7.2fbe9","type":"inject","z":"4ec0caef.1d59ac","name":"","topic":"","payload":"Default text","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":185.5,"y":160,"wires":[["a444821b.ba15c8"]]},{"id":"f26ba179.aaa478","type":"debug","z":"4ec0caef.1d59ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":705.5,"y":218,"wires":},{"id":"9b65de7c.212788","type":"ui\_group","z":"","name":"Save text","tab":"b0f1363e.50c5c8","disp":true,"width":"6","collapse":false},{"id":"b0f1363e.50c5c8","type":"ui\_tab","z":"","name":"test","icon":"dashboard","disabled":false,"hidden":false}]

bye

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 April 2019 17:31 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/3 "2019-04-17T17:31:42Z")

</div>

Hi your solution won't work for other users as the forum will change some parts of the code.

Always put code between three ticks  
`````  
`my code here`  
`````

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [17 April 2019 17:45 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/4 "2019-04-17T17:45:56Z")

</div>

I'm sure that @Grizzly's flow would work, but you could also try this:

 ![text-button](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a2e8b6d365307661d3495715f75f3e87409b901d.jpeg)

```auto
[{"id":"7fc6f8d9.8a57c","type":"q-gate","z":"1840f36c.5e3cc5","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","maxQueueLength":"1","keepNewest":true,"x":510,"y":120,"wires":[["ecf16095.5a10b"]]},{"id":"d59a26f1.30f738","type":"inject","z":"1840f36c.5e3cc5","name":"","topic":"","payload":"default text","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":180,"y":120,"wires":[["bd6db65b.de98e"]]},{"id":"bd6db65b.de98e","type":"ui_text_input","z":"1840f36c.5e3cc5","name":"Text","label":"input","tooltip":"","group":"c925f0a1.c2066","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"300","topic":"","x":350,"y":120,"wires":[["7fc6f8d9.8a57c"]]},{"id":"ecf16095.5a10b","type":"debug","z":"1840f36c.5e3cc5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":120,"wires":[]},{"id":"c3211e88.698d08","type":"ui_button","z":"1840f36c.5e3cc5","name":"","group":"c925f0a1.c2066","order":2,"width":0,"height":0,"passthru":true,"label":"Save","tooltip":"","color":"","bgcolor":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","x":350,"y":160,"wires":[["7fc6f8d9.8a57c"]]},{"id":"8760e8be.395cd","type":"inject","z":"1840f36c.5e3cc5","name":"","topic":"control","payload":"trigger","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":160,"wires":[["c3211e88.698d08"]]},{"id":"40b2d424.4b1ecc","type":"inject","z":"1840f36c.5e3cc5","name":"","topic":"","payload":"hello world","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":80,"wires":[["bd6db65b.de98e"]]},{"id":"c925f0a1.c2066","type":"ui_group","name":"Group 1","tab":"f1dc1ca1.c1457","order":1,"disp":true,"width":6},{"id":"f1dc1ca1.c1457","type":"ui_tab","z":"","name":"Text-Button","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

The node labelled `q-gate` is [node-red-contrib-queue-gate](https://flows.nodered.org/node/node-red-contrib-queue-gate), and it should do the job without any coding.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 April 2019 18:54 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/5 "2019-04-17T18:54:59Z")

</div>

What does the `q-gate` node do that the change node and a flow variable couldn't?

E.g...

- Text node --\> change node (copy `msg.payload` to `flow.text`)
- Button node --\> change node (copy `flow.text` to `msg.payload`) --\> debug node

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [17 April 2019 18:59 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/6 "2019-04-17T18:59:46Z")

</div>

> [@Steve-Mcl](#):
>
> What does the `q-gate` node do that the change node and a flow variable couldn't?

In this case, not a lot. Only that you can deploy as many instances as you want without having to edit each one to define a unique flow variable. If you check the README, you'll see that in general the node has a fair bit of flexibility.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 April 2019 19:03 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/7 "2019-04-17T19:03:15Z")

</div>

I was just curious. I try not to add too many extra nodes when something built in can handle it. Cheers.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [17 April 2019 19:28 UTC](https://discourse.nodered.org/t/how-to-combine-text-input-node-with-button-node/7871/8 "2019-04-17T19:28:34Z")

</div>

> [@Steve-Mcl](#):
>
> I try not to add too many extra nodes

Understood. I wrote [node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate) for my own use and only published it and a couple of related nodes a year or more later, because there seemed to be some [interest](https://discourse.nodered.org/t/gate-node-using-blockly/2830) on this forum. I don't think many people use them.
