Cannot populate repeating panel with flat list

I’m just trying to use a flat list as my repeating panel items but this does not seem to work.

According to the ‘RepeatingPanels’ documentation, I should be able to simply set a repeating panel’s items with

self.repeating_panel.items = ['a', 'b', 'c']

but this only results in a blank repeating panel. I have a repeating panel named ‘data_column_list’ which just uses labels for components. I try to set the labels to ‘a’, ‘b’, and ‘c’ using

self.data_column_list.items = ['a','b','c']

in the initialization, but when I run the app, the repeating panel is empty. Is it not actually possible to set repeating panel items with just a flat list?

Figured it out. It’s not well explained in the documentation, but the ‘items’ for a repeating panel are essentially an attribute which you can then apply to the components within the repeating panel. I just wasn’t doing that last step.

Once the repeating panel was constructed in the Design view, it created ItemTemplate1 within Form1. The labels I added as components to the repeating panel are within that ItemTemplate1. So I selected that and went to code view and added the following line to set the label text to the item value:

self.label_1.text = self.item
2 Likes

If I understand what you are doing, you don’t need to do this.

You usually assign a list of strings (or tuples) to items of a dropdown, while you usually assign a list of dictionaries to items of a repeating panel.

Anvil will automatically create one instance of the template form for each element in the list, then assign the list element to item of the form just instantiated.

For example this will create two forms in the repeating panel:

# in the form with the repeating panel
self.repeating_panel.items = [
    {'name': 'joe', 'age': 6},
    {'name': 'jane', 'age': 4},
]

# in the row template form
def form_open(self, **event_args):
    print(self.item)

You will see that each form prints is own dictionary when it is created. At this point you can add two labels to the form, then link their text property with self.item['name'] and self.item['age'] to see the labels automatically populated.

In this case I really did just want to assign a list of strings to a repeating panel. I’m using this to import a list of columns in a csv file, then let the user select which files they want to use in the rest of the app functions. So all I needed was to set the label_n.text of each row in the repeating panel to the column label in the data. The rest of the components in the repeating panel are actually going to be a radio button and a check box. Head over here to see that continuing saga:

1 Like