Dynamic list in node configuration

I wrote a custom node that generates a JSON payload. I would like to have the node configuration have an 'extra tags' list. The first version I wrote lets the user specify these extra tags as a json object:

{ "extraTag": "extraValue"}

but what I really want is to have it look like the injector node does, with a list of keys and values, and an [+add] button.

I'm not exactly sure how to do this, short of doing what Inject does - build it all up manually using jquery. Is there an easier way to make a list like this, or does it really necessitate custom everything? Are there other examples of nodes that have this sort of thing?

Kind of answering my own question here, but after lookign for more examples I found this:


which is used by two internal nodes: Change and Switch. That plus another example I found (not on my native language, but still understandable) got me, I think, on my way. One thing the German example had was it created a 'template' for the row. I think I'll do that as well.

HI @wz2b

Welcome to the forums.

There many many nodes that use the editable list (I am sure)
I am one of them.

Creating the list element

Populating the list from serialized data

This is called when clicking the add button and when populating data

Its also documented here.

Oh you found the docs :laughing:

I did. It took me a little while because i wasn't sure of the name of the thing I was looking for. Thanks for pointing me to some other examples. I have this mostly working:

  • It creates an empty list on startup
  • You can click the 'add' button and add rows
  • When I run the node, it does the right thing (the rows end up in the output payload)

What I don't have working yet is populating the UI list from the stored node configuration. I don't think I understand the semantics of addItem. It gets called (apparently) when one pushes the "add" button. Does this also get called with [data] = whatever the config field is set to when it starts? or does onprepareedit have to do that?

Actually I re-read what you said and you already answered the question: it happens in both cases. I just thought in the case where it's getting initially populated (I from the node def config data) that I would have seen node.something to pull it out of the config. Maybe I defined the variables wrong. In html registration I did this:

tags: {value: [], required: false}

In my node type definitino (which is typescript) I did this:

{ ... tags: Array<Array<string>> ...}

in other words, it's an array of arrays of strings like:

[ [ 'a', 'b'], ['c', 'd' ]] ]

I think I have it. Your zwave example was an immense help. Thank you for pointing me to it.

I noticed what you were doing in prepare was creating the list, then re-selecting it. One of the things I was doing wrong was assuming .editableList actually returned the list, so I then called eList('addItem') as if it was a function. Apparently that's not the case. I've lived my whole world in react and angular and just have no experience with jQuery, so this probably looks like a n00b mistake.

Glad your up and running.

You can see the the items being loaded on the switch node here.

You can add your items in bulk also in oneditprepare, but not sure if you then get an array in the addItem callback or its still triggered for each item.


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