Send message from a html input button on template back to node red

can i send a msg to the node red debug from a template node? i made a site with the http in - template - http out and i want that when i click a button (not a submit button, just a ) the node red debug receives some message like the value or anything.

i thought about change the msg.payload and return it on the debug but how do i do that? i already asked here how do i change a flow variable inside the template node but nothing yet

Read the built in help of the ui-template.

image

Search the forum: Search results for 'send message from template' - Node-RED Forum
e.g: Ui-template: sending msg through a function - #4 by Steve-Mcl

1 Like

can i do it on regular template?

Yes you can (I do this often, although I prefer websockets for interaction)

In template node, example

<button onclick="test()">to node-red</button>
<script>
function test(){
const send = fetch("http://your-node-red-ip:1880/yoururlendpoint?clicked=true")
}

</script>

attach a debug node to the http-in node, look for the payload when the button is clicked.

SCR-20221031-kp7

1 Like

My appologies, I completely threw the part about using http-in nodes out of my brain and ploughed for the usual dashboard example.

As @bakman2 points out - you have to take care of posting data from the front-end to the back end & has provided a working example too.

My only advice would be use a parameterised endpoint e.g. web1/api/v1/:fn then you can post to URLs like web1/api/v1/create or web1/api/v1/update or web1/api/v1/delete and in your function test what is in msg.req.params.fn to route your messages as required by the intended fn.

2 Likes

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