Get the current value of multiple input nodes on button click

I want do create a form flow. This flow should consist of multiple input nodes (including a dropdown node) and a submit button node.
To the best of my knowledge the form node does not support dropdown or choice fields, so i have to build my own.

I want to store the values of the input nodes in a database when submit is clickt. My question is, how to achieve this with Node-RED?

In my understanding the dashboard input fields cannot be configured to only send the input when a specific message is received. So i need a flow to capture all these messages and only stores the most recent one. If a trigger message is received, this flow would pass on the most recent value of each input.

Use a Join mode in Manual mode, set to generate Key/Value object, Number of message parts 1 and select And Every subsequent message. Feed all the input nodes into that and also the Submit button. Make sure each input and the button have unique topic strings. Put a debug node on the output and you will see that each time there is any input or the button you will get a message where the payload contains all the latest previous values for each input. Initially they will not all be there if there has been no value from that input. Note that the topic of the message out tells you which input has been received, so put a Switch node on the output set to only pass messages where the topic is that of the button. Then each time the submit button is pressed you will get a message containing all the latest values.

Thanks for your solution.
I did add a small function node to reset the submit state. Before that each change was submitted after the first submit press.
Here is my complete flow:

[
    {
        "id": "e818bf95.b4fc3",
        "type": "tab",
        "label": "Wassertest",
        "disabled": false,
        "info": ""
    },
    {
        "id": "2acab28d.4e6a5e",
        "type": "ui_dropdown",
        "z": "e818bf95.b4fc3",
        "name": "",
        "label": "Testing Method",
        "tooltip": "",
        "place": "Select a testing method",
        "group": "e6377050.f6aa5",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [
            {
                "label": "PH Meter",
                "value": "ph_meter",
                "type": "str"
            },
            {
                "label": "Drop Check",
                "value": "drop_check",
                "type": "str"
            }
        ],
        "payload": "",
        "topic": "method",
        "x": 630,
        "y": 340,
        "wires": [
            [
                "7726c281.a4886c"
            ]
        ]
    },
    {
        "id": "617c4cfa.e7ac04",
        "type": "ui_button",
        "z": "e818bf95.b4fc3",
        "name": "",
        "group": "e6377050.f6aa5",
        "order": 2,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Submit",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "submit",
        "x": 620,
        "y": 500,
        "wires": [
            [
                "7726c281.a4886c"
            ]
        ]
    },
    {
        "id": "3be680fe.a0378",
        "type": "ui_text_input",
        "z": "e818bf95.b4fc3",
        "name": "",
        "label": "pH Value",
        "tooltip": "1-14",
        "group": "e6377050.f6aa5",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "number",
        "delay": "1",
        "topic": "ph_value",
        "x": 620,
        "y": 420,
        "wires": [
            [
                "7726c281.a4886c"
            ]
        ]
    },
    {
        "id": "7726c281.a4886c",
        "type": "join",
        "z": "e818bf95.b4fc3",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 910,
        "y": 380,
        "wires": [
            [
                "b4389e80.f0706"
            ]
        ]
    },
    {
        "id": "8c640303.6b241",
        "type": "debug",
        "z": "e818bf95.b4fc3",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1350,
        "y": 380,
        "wires": []
    },
    {
        "id": "b4389e80.f0706",
        "type": "switch",
        "z": "e818bf95.b4fc3",
        "name": "",
        "property": "payload.submit",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1110,
        "y": 380,
        "wires": [
            [
                "8c640303.6b241",
                "640a24cd.07db7c"
            ]
        ]
    },
    {
        "id": "640a24cd.07db7c",
        "type": "function",
        "z": "e818bf95.b4fc3",
        "name": "",
        "func": "msg2 = {'topic': 'submit', 'payload': false};\nreturn msg2;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1020,
        "y": 480,
        "wires": [
            [
                "7726c281.a4886c"
            ]
        ]
    },
    {
        "id": "e6377050.f6aa5",
        "type": "ui_group",
        "z": "",
        "name": "pH",
        "tab": "67bc0279.6d37ac",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "67bc0279.6d37ac",
        "type": "ui_tab",
        "z": "",
        "name": "Water Testing",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

You have not configured the switch quite as I suggested, it should be testing the topic. LIke this
image

Then you can take the function node out. The reason it works is that the topic in the message from the Join node is that of the most recent message received

1 Like

Thanks again. Applied your correction. Everything is working as expected.

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