The great thing about repeating panels:
set the items with a list of length n → n item_templates appear with the item property set
The not so great thing about repeating panels:
If the list is long or the item_template has many data_bindings the form can take a long time to load
If the list changes, say by deleting an item or adding an item, then it can be a UI nightmare
to have to repopulate the item_templates of a repeating_panel
deleting an item works well:
You don’t need to use repeatin_panel.items =
and so each item_template doesn’t have to be repopulated ![]()
You can do something like…
# in the item_template form
def delete_button_click(self, **event_args):
self.parent.raise_event('x-delete-item', item=self.item)
self.remove_from_parent()
===================================================================================
# in the form with the repeating panel
def __init__(self, **properties):
self.repeating_panel.set_event_handler('x-delete-item', self.delete_item)
def delete_item(self, item, **event_args):
self.repeating_panel.items.remove(item)
adding an item isn’t so great
The only thing I can come up with is what has been suggested here by @daviesian :
You have to repopulate all the item_templates in order to append a single item_template,
which can be slow.
def add_button_click(self, **event_args):
self.repeating_panel.items = self.repeating_panel.items + [{'foo':'bar'}]
What if a repeating_panel had an add_component method:
add_component(item=)
To me, this makes sense since a repeating panel has an item_template so calling add_component would just add a new item_template with that item.
def add_button_click(self, **event_args):
item = {'foo':'bar'}
self.repeating_panel.items.append(item)
self.repeating_panel.add_component(item=item)
Not doing repeating_panel.items = means we don’t repopulate all the item_templates ![]()
Extension
If you know you have a long list of items you could populate some of the items in the init method and then the rest of the items in the form_show event
def __init__(self, items=None, **propeties):
self.items = items
self.repeating_panel.items = items[:3]
def form_show(self, **event_args):
for item in self.items[3:]:
self.repeating_panel.items.append(item)
self.repeating_panel.add_component(item=item)
