Dynamic number of items in a widget

Is there a way to add an array item when defining props in a widget? For example I have this items below and I want to have like an array/list where I can add any number of items inside it:

I only want to achieve this through the widget and not from a rule.

The simplest solution would be to use a group item as input. If you need additional information for each item you could either use nested groups or custom item metadata.

If you give your Items custom Tags, you can use the oh-repeater in your widget to get all Items with this Tags.

1 Like

In most situations, the group and tag options mentioned above are your best solutions, especially if you are then using an oh-repeater to get detailed api data about items. However, there is a built-in solution for more general arrays in parameters: the multiple property.

For example, the paramter:

    - name: itemArray
      label: Items
      type: TEXT
      context: item
      description: A list of items
      multiple: true

Will open up the item picker with checkboxes:


which allows you to selecte multiple items and the returned property just uses basic array indexing: props.itemArray[1].

The same is actually true for a text field as well. Adding multiple: true turns the text parameter input from a simple input box to a multiline textarea input and each line is an element in the returned array.

    - name: textArray
      label: Text list
      type: TEXT
      description: An array of text values
      multiple: true

image
And props.textArray[1] returns banana.

1 Like

Wow, I didn’t know that. Thank you for sharing!