With a custom node's parameter configuration editor, I'd like to convert a multi-line textarea's content from a single string to a list of strings, one per line.
Here is how I tried it with mynode.html
oneditsave: function() {
var node = this;
var nameText = $("#node-input-names").val();
var names = nameText.split('\n');
console.log(`node: ${Array.isArray(names)}`);
node.names = names;
}
When saving the node in the editor, I can see the print out "node: true", meaning the text extracted from textarea has been converted to an array of strings.
However, in mynode.js, I plugged
function myNode(this, config) {
...
console.log(`config.names is array: ${Array.isArray(config.names)}`);
...
This time I got
config.names is array: false
where I expect it to be
config.names is array: true
I also tried to set the textarea content in oneditsave() and that works as long as I provide a string to it.
What am I missing? Is it that I'm not allowed to convert variable types there?
The reason why I don't use an EditableList widget is because the lists in our cases are usually too big to fill in one by one by hand using the "add" button. I'd love to ask my users to use a plaintext format with one item per line, then convert it back to a list automatically using a parser on saving the configuration.