Store and Restore dynamic node UI properties

I wrote a node that has a dropdown list property (field?) that is used to basically define the function of the Node. Some of the functions have additional properties. So I wrote the node to dynamically add the labels and input boxes for the additional properties. Basically, you see a different set of properties depending on which function you selected. When the function field changes, the div containing the html is deleted, and then recreated from the corresponding mustache template. Visually, it works perfect. The problem is my properties are not persistent.

What is the mechanism that Node Red uses to identify data it needs to persist? Something I’m doing with dynamically generating the properties is making it not persist. When I click save, close the dialog, and reopen it, my dynamic properties are back to empty. Is there anything I can do to ensure they persist? Or am I bending Node Red too far?

In the abstract what you're trying to do can be done. In the concrete, well... you didn't post any HTML or JS snippets, so there's nothing concrete to look at...

You need to put the values into the HTML input elements, that's where NR gets the values to stick into the fields. The input elements need to have IDs that use the naming pattern.

It might be safer to define them all from the start, and hide the ones you don't want when necessary. So they still exist but are not visible.

You must predefine all properties on the node object as described in the docs: Node properties : Node-RED

This is how the editor knows what properties to include when exporting the node.

But this just applies to the top level properties of the node object itself.

If you want dynamic properties, then you could define a single top-level 'props' property as an object, and then add whatever custom properties you want under that using the oneditprepare and oneditsave functions.

You'd lose all the built-in convenience of top-level property handling such as validation and error reporting, but it would be one way to do it.

This might help..

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