Can you pass data to the HTML file of a node?

I would like to pass a list to the html file to display it in a dropdown, and pass back the selected item when the node is initialized.
Is there a way to pass data from the node's js file to the html?

Yes

inject (set to inject at initialisation) --> file in --> something --> ui_dropdown

where something is a function or JSON or other node that turns your text into a JS array & sends it in msg.options to the ui_dropdown in the required format as per the dropdown nodes built in help....

The Options may be configured by inputting msg.options containing an array. If just text then the value will be the same as the label, otherwise you can specify both by using an object of "label":"value" pairs :
[ "Choice 1", "Choice 2", {"Choice 3":"3"} ]

Maybe I was not specific enogh.
So I embedded node red to my app and now I am creating custom nodes.
The idea is that tha app is passing data to the the js part(https://nodered.org/docs/creating-nodes/node-js) of the custom node and the js sends data to the front-end(the nodes editor page https://nodered.org/docs/creating-nodes/node-html). The data should be there when I am opening the nodes editor page without linking the node to any other nodes.

Passing the list back to your node's js file is just a matter of including it in the config parameters. Getting a dynamically created list of values into the Editor requires an API call. Easy enough to do in the html file since it includes JQuery. The API is usually done using Node-RED's Express app but if you are running in embedded mode, you will probably have to add a route to the custom ExpressJS API in your own code.

The serial nodes are often quoted as an example of how to do this. Take a look at the code.

My own uibuilder node makes use of several API's in the Editor so that I can pass file contents back and forth and check whether a url has already been used for example.

1 Like

Ah my apologies. Yes. But I can't answer from phone right now. Will point you in the right direction tomorrow if someone doesn't give you a heads up in the mean time.

Edit ^ seems Julian is there with am answer as I was typing :slight_smile:

I guess it was a bad question, not a bad answer. :slight_smile:

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