Sending user input in a UI Template as a msg.payload

I am new to node-red and have been trying to use a UI template node to allow a user to enter multiline comments. I want to output the entered text as a string to msg.payload and this is the closest I have been able to get.

<html>
  <body>
      <label for="text">Additional Comments:</label>
      <textarea id="textentered" rows="8" cols="25"></textarea>
      <input type="submit" value="Save Comments" ng-click="send({paylod:test()})">
  </body>
</html>
<script>
    function test() {
        var user = document.getElementById("textentered").value;
        msg.payload = user;
        return msg;
    }
</script>

everytime you use a ui-template or other dashboard ui nodes its basically an angular component (i think)
.. so most of your code should be done through angularjs which is the front-end language the dashboard is using.


      <label for="text">Additional Comments:</label>
      <textarea id="textentered" rows="8" cols="25"></textarea>
      <input type="submit" value="Save Comments" ng-click="send({payload:test()})">

<script>

(function(scope) {

    scope.test = function() {
        console.log("TEST!!!!")
        var text = document.getElementById("textentered").value;
        return text;
        // msg.payload = user;
        // return msg;
    }

})(scope)

</script>

.. and you dont need html and body tags as those are already loaded in the main document .. your additional html and code will be injected in that placeholder when you deploy and all variables and functions need to be added to the scope of that angular component .. complicated stuff :wink: .. but you can study the examples on the ui-templates help tab

1 Like

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