Access config node properties from HTML

I am developing a node that is configured with a config node. In the .js file, I can access the config node using RED.nodes.getNode(n.config);. How can I access the config node from the HTML?

My config node defines two fields keyName and valueName. In the actual node, I have a select field with the following two options:

<option value="key">key</option>
<option value="value">value</option>

I would like to change the text for these options based on the keyName and valueName properties of the currently selected config node.

I think the best way for doing so (but please correct me if I'm wrong) would be to have something like the following in the oneditprepare function:

$("#node-input-config").change(function() {
   // The following doesn't work on HTML, how can I get the config node in HTML?
   var config = RED.nodes.getNode($(this).val()); 
   $('#node-input-select option[value="key"]').text(config.keyName);
   $('#node-input-select option[value="value"]').text(config.valueName);

There is a slight inconsistency between the runtime and editor's apis here.

Use RED.nodes.node(...) in the editor.

Remember to handle the case where a user has not yet added a config node so there is no such node.

1 Like

Great, thanks! It works now :slight_smile:

Hey Guys,

Is there any way to access the runtime of config JS file. For an example I have created a connection to a cloud server inside the config node's JS file. I can access this in other JS files using RED.nodes.getNode. But in the HTML, I only can get the text box values using RED.nodes.node. Is there any way to access the JS runtime ? or do I have to handle these connections separately

I can't find documentation for RED.nodes.node() and its argument(s). Where is this documented at?

The editor apis are not fully documented. RED.nodes.node() takes a single argument - the id of the node you want.