Array of Keys / Values

Few things…

This option on the plugin builder ‘fields’ section just popped up for me the other day. I’ve been using the plugin builder for about 8 months now. I though this was a new feature so went to the forums to read about it and it apparently has been around since 2019. Is there a reason I wouldn’t have seen this option until now?

Now for the bigger issue. Using this feature I’d assume it would return an array as

[
{key_name : value_name}
]

but it doesn’t. Its outputting:

[
{key: key_name, value: value_name}
]

which gets interpreted as ‘key’ & ‘value’ are the keys, and then ‘key_name’ & ‘value_name’ are the values.

Next if you add more than one key:value pair it puts each one into its own object within the array…

[
{key1: key1, value1: value1}
{key2: key2, value2: value2}
]

Now thats not that big of a deal but typically if you are given more than one key:value pair it typically goes into one object, right? Which leads to the next problem. If you try to do lists with this here is what it outputs…

Which now you can’t guarantee the correct quantity with the correct price (at least for this example) which limits this entire feature to only accepting one thing. Kind of becomes useless at that point.

Am I doing something wrong here, or is this normal behavior? and has anyone used this feature successfully?

Last, as the plugin developer shouldn’t we be specifying what the ‘keys’ are? Not the person using the plugin because they don’t know what keys to enter unless we tell them. We already get to specify what fields show, why not the keys?

Also, quick side note, does console.log() not work? can’t get anything to print to the console.

You should think about a “field” as a key.

Essentially we are supplying the plugin component a properties object.

Each field is a key. When you create the field you type it by specifying what kind of input the field should be. Hence you specify the keys value type.

This key/value input is definitely a bit more advanced. I’ve used this with a table plugin previously.

1 Like

Yea I do understand that a “field” is a key. and thats what I’m saying. We specify the fields and basically define what the ‘key’ is by putting it in the name box. So we know what to put in the code.

But using the array of key/value pair option. The user enters the key, not the plugin developer, so now we have no idea what they have entered without a lot of extra JS to find what they entered and rebuild a new object with the correct key:value pairs.