I’m trying to access a repeating panel from it’s item template as described in the documentation.
What I’ve tried and what’s not working:
I’ve tried accessing self.parent from the item template but it returns None
Code Sample:
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.repeating_panel_1.var1 = 'test'
self.repeating_panel_1.items = ['foo', 'bar', 'buzz']
class ItemTemplate1(ItemTemplate1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
print(self.parent) # returns None
print(self.parent.var1) # causes an error
Is the show event just called show without any underscores? This doesn’t print anything:
class ItemTemplate1(ItemTemplate1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.label_1.text = self.item
def show(self):
print(self.parent)
print(self.parent.var1)
Alternatively, calling self.show() at the end of the init produces the same error as having the code in the init itself.
Edit: Ah, I had to set the show event from the design panel too. My bad.
Referencing self.parent from the show event does indeed work and returns the expected object.
However, I would also expect it to work in the __init__ if it’s after self.init_components(**properties)
Picture the code that creates the instances of the repeating panel row template to add to the repeating panel. It would be something like this:
# this is the point where __init__ is called
new_row = RowTemplate()
# this is the point where form_show is called and
# the row's self.parent is set up
self.add_component(new_row)
So self.parent is None in __init__ because the row hasn’t been added to the repeating panel yet.