Re: [node-red] two text inputs combine into a string on dashboard button press

2,435 views
Skip to first unread message

Zenofmud

unread,
Apr 8, 2017, 9:53:46 AM4/8/17
to node...@googlegroups.com
Providing your current flow will help.

As I understand the text input, as soon as you leave the field, the message is sent to the node. If you use a form, they wot be sent until you press the submit button. So if the two fields are entered at the same time you could use that method.

If they are being entered separately and at different times, then you will have to store them in a global or database and wait till you have both to pass them on. You will also have to determine when/how to reset the globals (should it reset if only one entry in ten minutes etc)

Paul
 
On Apr 8, 2017, at 8:32 AM, Matty <mattr...@gmail.com> wrote:

i am very new to red node and am trying to figure out how to take 2 dashboard text inputs and combine the two into a string to send to the debugger (for now, im going to pass it via exec to a python script) only when the button is pressed.

text input = number eg 5551234
text input = message eg this is the message
button = when pushed should combine into a string "5551234" "this is the message" 

I have the number and message coming through to debugger, but I only want it to combine the two strings when i press the button.
any ideas?
Thanks






--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/3d8bd9a4-fd3c-4ff7-bebb-22124fd8966b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zenofmud

unread,
Apr 8, 2017, 10:04:17 AM4/8/17
to node...@googlegroups.com
Matty,

Here is a sample flow with the text inputs, a form input and a template input so you can see the difference.

[{"id":"2061849f.d4a634","type":"debug","z":"fb39137e.04c6f","name":"","active":true,"console":"false","complete":"true","x":627,"y":191,"wires":[]},{"id":"f5e77642.b28b5","type":"ui_text_input","z":"fb39137e.04c6f","name":"","label":"Height","group":"cd93ac2d.e3df68","order":2,"width":"2","height":"1","passthru":true,"mode":"text","delay":"0","topic":"","x":288,"y":142,"wires":[["2061849f.d4a634"]]},{"id":"27fe9594.2cdcaa","type":"ui_text_input","z":"fb39137e.04c6f","name":"","label":"Width","group":"cd93ac2d.e3df68","order":3,"width":"2","height":"1","passthru":true,"mode":"text","delay":"0","topic":"","x":285,"y":193,"wires":[["2061849f.d4a634"]]},{"id":"d744ae75.c373","type":"ui_text_input","z":"fb39137e.04c6f","name":"","label":"Length","group":"cd93ac2d.e3df68","order":4,"width":"2","height":"1","passthru":true,"mode":"text","delay":"0","topic":"","x":284,"y":241,"wires":[["2061849f.d4a634"]]},{"id":"c68bdb2f.9c5ef8","type":"ui_text_input","z":"fb39137e.04c6f","name":"","label":"Potter ID","group":"cd93ac2d.e3df68","order":1,"width":"2","height":"1","passthru":false,"mode":"text","delay":"0","topic":"","x":298,"y":92,"wires":[["2061849f.d4a634"]]},{"id":"dc4e747d.26fc3","type":"debug","z":"fb39137e.04c6f","name":"","active":true,"console":"false","complete":"true","x":352,"y":354,"wires":[]},{"id":"b1fd91c.5d051f","type":"ui_form","z":"fb39137e.04c6f","name":"Firing Slips entry","label":"label","group":"5cc59946.ca757","order":1,"width":"12","height":"1","options":[{"label":"ID","value":"potter","type":"text","required":true},{"label":"Height","value":"height","type":"number","required":true},{"label":"Width","value":"width","type":"number","required":true},{"label":"Length","value":"length","type":"number","required":true}],"formValue":{"potter":"","height":"","width":"","length":""},"payload":"","topic":"","x":114,"y":354,"wires":[["dc4e747d.26fc3"]]},{"id":"8b7b9f7d.668c6","type":"comment","z":"fb39137e.04c6f","name":"Test 1: using text input fields","info":"","x":153,"y":44,"wires":[]},{"id":"56a5a8fe.e8747","type":"comment","z":"fb39137e.04c6f","name":"Test 2: using form","info":"","x":121,"y":296,"wires":[]},{"id":"1d762a68.70aff6","type":"comment","z":"fb39137e.04c6f","name":"Test 3: using a template form","info":"","x":154,"y":422,"wires":[]},{"id":"e46ee032.9a605","type":"template","z":"fb39137e.04c6f","name":"test","field":"payload","fieldType":"msg","format":"html","syntax":"plain","template":"<!DOCTYPE html>\n<html>\n<body>\n<form id=\"frm1\">\n  First name: <input type=\"text\" name=\"fname\" value=\"Donald\"><br>\n  Last name: <input type=\"text\" name=\"lname\" value=\"Duck\"><br><br>\n</form> \n\n<p>Click \"Try it\" to display the value of each element in the form.</p>\n\n<button onclick=\"myFunction()\">Try it</button>\n\n<p id=\"demo\"></p>\n\n\n<script>\nfunction myFunction() {\n    var x = document.getElementById(\"frm1\");\n    var text = \"\";\n    var i;\n    for (i = 0; i < x.length ;i++) {\n        text += x.elements[i].value + \"<br>\";\n    }\n    document.getElementById(\"demo\").innerHTML = text;\n}\n</script>\n\n\n</body>\n</html>","x":265.26197052001953,"y":488,"wires":[["376260b2.2fdc"]]},{"id":"f2e2cfb4.80182","type":"inject","z":"fb39137e.04c6f","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"x":98,"y":488.7142515182495,"wires":[["e46ee032.9a605"]]},{"id":"d0cce2cc.50f14","type":"debug","z":"fb39137e.04c6f","name":"","active":true,"console":"false","complete":"true","x":626,"y":487,"wires":[]},{"id":"376260b2.2fdc","type":"ui_template","z":"fb39137e.04c6f","group":"37a533ed.5f2a24","name":"manual form","order":5,"width":"6","height":"6","format":"<div ng-bind-html=\"msg.payload | trusted\">div here</div>","storeOutMessages":false,"fwdInMessages":false,"x":435,"y":487,"wires":[["d0cce2cc.50f14"]]},{"id":"cd93ac2d.e3df68","type":"ui_group","z":"","name":"Firing Slips","tab":"727b20bf.8f0ae","order":1,"disp":true,"width":"12"},{"id":"5cc59946.ca757","type":"ui_group","z":"","name":"Pottery Form","tab":"727b20bf.8f0ae","order":2,"disp":true,"width":"12"},{"id":"37a533ed.5f2a24","type":"ui_group","z":"","name":"Pottery Template Form","tab":"727b20bf.8f0ae","order":1,"disp":true,"width":"6"},{"id":"727b20bf.8f0ae","type":"ui_tab","z":"","name":"Pottery","icon":"dashboard","order":3}]

Alf32

unread,
Mar 13, 2018, 10:41:38 PM3/13/18
to Node-RED
Does anyone know how to send the input text combination as msg.payload instead of to the debugger for the case of "Pottery Template Form" that you show?
Pottery Template Form.png

Zenofmud

unread,
Mar 14, 2018, 4:11:33 AM3/14/18
to node...@googlegroups.com
Here is an example that will pass the text fields back to the flow. You can see them in the debug node in msg.payload,

[{"id":"e42e1d22.d1e1f8","type":"comment","z":"fb39137e.04c6f","name":"Test 3: using a template form","info":"","x":160,"y":240,"wires":[]},{"id":"77515e20.825958","type":"inject","z":"fb39137e.04c6f","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":300,"wires":[["61ba4e2f.c8d2d"]]},{"id":"b00338e9.30c768","type":"debug","z":"fb39137e.04c6f","name":"","active":true,"console":"false","complete":"true","x":630,"y":300,"wires":[]},{"id":"61ba4e2f.c8d2d","type":"ui_template","z":"fb39137e.04c6f","group":"37a533ed.5f2a24","name":"manual form 3","order":5,"width":"6","height":"6","format":"<script>\n// or overwrite value in your callback function ...\nthis.scope.action = function() {\n     var x = document.getElementById(\"frm1\");\n    var value = \"\";\n    var i;\n    for (i = 0; i < x.length ;i++) {\n        value += x.elements[i].value + \"<br>\";\n    }\n    document.getElementById(\"demo\").innerHTML = value;\n return value; \n }\n</script>\n\n<form id=\"frm1\">\n  First name: <input type=\"text\" name=\"fname\" value=\"Donald\"><br>\n  Last name: <input type=\"text\" name=\"lname\" value=\"Duck\"><br><br>\n</form> \n\n<p>Click \"Try it\" to display the value of each element in the form.</p>\n\n<md-button ng-click=\"send({payload:action()})\">\nTry it\n</md-button>\n\n<p id=\"demo\"></p>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":380,"y":300,"wires":[["b00338e9.30c768"]]},{"id":"37a533ed.5f2a24","type":"ui_group","z":"","name":"Pottery Template Form 2","tab":"727b20bf.8f0ae","order":1,"disp":true,"width":"6","collapse":false},{"id":"727b20bf.8f0ae","type":"ui_tab","z":"","name":"EXAMPLE: Inputs","icon":"dashboard","order":1}]
Reply all
Reply to author
Forward
Message has been deleted
0 new messages