Hey all,
I've created an input field in the template node and I just want to extract it to use in my flows.
Here's the basic input field (without the brackets): input type="text" name="joel"
And then I'd like to take the users input and do something with it. How can I access the value in the html input field and use it in my node-red flow logic?
Thanks @krambriw that makes sense. But how do I reference the input field value in {payload: ${JSvariable??}}
I can't seem to find the correct method...
I suppose you are inside the template nodes html code now? To send something initiated via the web page defined in the template node, I typically have html code when I click the mouse button like this:
Great, good to hear!
It is very powerful to use, I have built some nice web pages using template nodes, showing all kind of info including live videos, buttons to control lamps etc etc
@krambriw hopefully last question - how would I pre-populate html input fields in a template node with variables from a javascript function? I am trying the following in an attempt to set the temp1 field with the value from an array payload[0].temp :
<head>
<script>
var test = {{payload[0].temp}};
let fetchTemp = () => {
document.getElementById("temp1").value = test;
}
</script>
</head>
<body>
<button onMouseDown="fetchTemp()">Assign temp</button>
</body>
As you have no doubt found out, you cannot substitute payload values into your <script> ... </script> elements. Instead, you need to use the scope.watch code that Walter provided earlier to get the msg and update the element with the new value.
Also, your template source is NOT a complete html page -- so any <head> ... </head> elements are ignored. Only the body portion of your template in inserted into the overall Dashboard page layout. If you really need something added to the head of the dashboard, put it into a separate ui_template and select Template Type: "Added to site <head> section"
I have looked for days how to do that
and everything refers to scope.$watch()
kind of things that never worked on what I want.
I can not believe it was so simple. Thank you very much.
This should be included in ui_template documentation instead of
the current example imho.