Confirmation button before sending out data

How would you do this:

You select your data via a dropdown, textfield or whatever and when you are finished you have like a submit button, so like a confirmation before you send data further in the flow.

Should you go for a button node, a form, a template,.... ?

The issue is when I select data from a dropdown list now it immediately sends the data further up the flow (In my case an SNMP set node) But if you select the wrong value in the list you could really screw up. So like a "confirmation/send button" would be practical.

Are you talking about the node-red-dashboard or a node you are creating?

Node-red dashboard. So within the pre-defined tools of the palette.
As a beginner I have to stick to that.

So I have moved this into the channel that is just for the #dashboard

Have your drop-downs and text fields feed into change nodes that store there payloads into flow context e.g flow.mib etc.

Then have a button that performs the operation you want after all fields are complete.

You could even have the button feed into a function node to verify users input.

Simple function node code that may give you some ideas....

var mib = flow.get("mib")
var val=flow.get("val");
if(!mib){
  node.error("mib is empty");
  return null;// halt flow / don't pass msg to next node
}
if(!val){
  node.error("val is empty");
  return null;// halt flow / don't pass msg to next node
}
msg.payload ={
  mib : mib, val : val
}
return msg;

Give it a try then if you get stuck, post your progress and issue here and someone will help.

1 Like

So if I use a flow instead off msg a button will work ?
I just added the change node to set msg.payload to flow.mib and I believe the function has a problem already.

[{"id":"7d9a835b.ba0d1c","type":"ui_dropdown","z":"3b93f73c.7a4e48","name":"","label":"","tooltip":"","place":"Select option","group":"ee8b6e07.f565e","order":11,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"},{"label":"14412","value":"1441200000","type":"str"}],"payload":"","topic":"","x":220,"y":480,"wires":[["f832d303.08759"]]},{"id":"96e10326.5b816","type":"function","z":"3b93f73c.7a4e48","name":"","func":"msg.payload = flow.mib;\nmsg.varbinds = [\n    {\n        \"host\": \"192.168.0.34\",\n        \"version\": \"1\",\n        \"oid\":   \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n        \"type\":  \"OctetString\",\n         \"value\": \"\"+msg.payload+\"\"\n    }\n]\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":480,"wires":[["b6a29476.7dd068"]]},{"id":"b6a29476.7dd068","type":"snmp set","z":"3b93f73c.7a4e48","host":"192.168.0.34","community":"public","version":"1","varbinds":"","timeout":5,"name":"","x":800,"y":480,"wires":[]},{"id":"f832d303.08759","type":"change","z":"3b93f73c.7a4e48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mib","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":580,"wires":[["96e10326.5b816"]]},{"id":"ee8b6e07.f565e","type":"ui_group","z":"","name":"SET","tab":"f0a3f99c.51e178","disp":true,"width":"6","collapse":false},{"id":"f0a3f99c.51e178","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

not quite. You have several issues in your flow.

  1. Dont use flow.mib. Use flow.get("mib") as per my example code
  2. You have the change node the wrong way around
  3. You are still feeding the dropdown directly into the SNMP function (i.e. there is no button)

Look at this example...

Here is the flow...

[{"id":"fbd40f86.852f8","type":"ui_dropdown","z":"4d4cd124.3da23","name":"","label":"","tooltip":"","place":"Select option","group":"c8d83136.ccafb","order":2,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"},{"label":"14412","value":"1441200000","type":"str"}],"payload":"","topic":"","x":120,"y":160,"wires":[["19557639.77855a"]]},{"id":"1a413224.98f57e","type":"function","z":"4d4cd124.3da23","name":"Check user input and construct varbinds","func":"var host = flow.get(\"host\");\nvar mib = flow.get(\"mib\");\nif(!host){\n    node.error(\"host is empty\",msg)\n    return null; //halt flow\n}\nif(!mib){\n    node.error(\"mib is empty\",msg)\n    return null; //halt flow\n}\n\nmsg.varbinds = [\n    {\n        \"host\": host,\n        \"version\": \"1\",\n        \"oid\":   \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n        \"type\":  \"OctetString\",\n         \"value\": mib\n    }\n]\n//temporary debug - set payload with string version for demo notification\n\nmsg.payload = \"All fields OK. This is what varbinds contains...\\n\" +  JSON.stringify(msg.varbinds);\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":340,"wires":[["c1cb63eb.75689","542e8ba8.3278b4"]]},{"id":"19557639.77855a","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"mib","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":160,"wires":[[]]},{"id":"a363a4de.2942a8","type":"ui_text_input","z":"4d4cd124.3da23","name":"","label":"Host","tooltip":"","group":"c8d83136.ccafb","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"200","topic":"val","x":110,"y":220,"wires":[["3d7d36c3.cf654a"]]},{"id":"3d7d36c3.cf654a","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"host","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":220,"wires":[[]]},{"id":"3545c6e2.03732a","type":"ui_button","z":"4d4cd124.3da23","name":"","group":"c8d83136.ccafb","order":3,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":110,"y":340,"wires":[["1a413224.98f57e"]]},{"id":"c1cb63eb.75689","type":"debug","z":"4d4cd124.3da23","name":"To SNMP (view result in debug window)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":460,"y":420,"wires":[]},{"id":"542e8ba8.3278b4","type":"ui_toast","z":"4d4cd124.3da23","position":"top right","displayTime":"4","highlight":"green","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":530,"y":300,"wires":[]},{"id":"fb1faea6.69f62","type":"catch","z":"4d4cd124.3da23","name":"","scope":null,"uncaught":false,"x":120,"y":520,"wires":[["e72e4047.df5bf"]]},{"id":"4f9d7d2d.ea0244","type":"ui_toast","z":"4d4cd124.3da23","position":"top right","displayTime":"4","highlight":"red","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":470,"y":520,"wires":[]},{"id":"e72e4047.df5bf","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":520,"wires":[["4f9d7d2d.ea0244"]]},{"id":"c8d83136.ccafb","type":"ui_group","z":"","name":"SET","tab":"f04ca30d.9a3d7","disp":true,"width":"6","collapse":false},{"id":"f04ca30d.9a3d7","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

Shameless self-promotion: node-red-contrib-queue-gate has a feature designed for almost exactly this case. It can be configured to retain the most recent message and release it when it receives a trigger. (This is described in the README.) If you try it and have any difficulty, please ask.