Assign label text en masse

A little improvement to @mark.breuss example (forgive me if this is obvious, I don’t know your beginnerness level) would be to use dictionaries in the values list:

values = [
    {'col1': 'abc', 'col2': 'def'},
    {'col1': '123', 'col2': '456'},
]

So when you create a new instance with CustomCompoent(value) you pass all the values for its fields.

Then you can do self.item = values in the __init__ and get all populated with data binding.

Another alternative is to use a repeating panel instead of using a container and adding components one by one.

The repeating panel is a container that automatically adds forms to itself and populates each form when you do self.items = list_of_dictionaries_with_values. This one liner takes care of adding forms to the container, assigning a dictionary to the item member of the form and triggering its data binding.

A repeating panel will list your forms vertically rather than side by side. You could play with CSS to get them to show side by side (but that would be more difficult and time expensive and less readable and maintainable than following Mark’s suggestion and creating your own loop).

1 Like