Search code examples
javascriptnode-red

How to edit specific code in a Node-Red Dashboard node


I have an object with 140 properties. It contains some configuration settings, and I want to let the user easily change them.

I want to generate a form having each of these properties as an element, like this Dashboard ui_form:

ui_form

But each of these elements needs me to set a name, label, etc., so I tried to automate the process and generated an array of elements as follows:

elements = [
    {"label":"Valve field count",
    "value":"valve_field_count",
    "type":"number",
    "required":false,
    "rows":null},
    {"label":"Valve fertilizer count",
    "value":"valve_fertilizer_count",
    "type":"number",
    "required":false,
    "rows":null},
    //etc
]

I formatted it this way after seeing the Info on the Form node (in the navigation to the right).

Now that I've set some of the settings for the form, how may I plug it into the form?


Solution

  • Solved with my friend's help:

    1. Export the node as JSON. Select the node, go to menu -> Export -> JSON tab, then either copy-paste somewhere or download.
    2. The node is an array of objects. One of those objects is of the type "ui_form". In this object, edit the property "options", and replace the array with my own generated array (called elements in my question). enter image description here
    3. After editing the JSON file in whatever program (make sure to save it as .json), import it back into Node-Red. Node-Red will complain that you're importing something you already have, but you can ignore it.
    4. You can then feed whatever values into the node.