import
gets you the class
of the Form; that is, a factory for making instances of that class
: for making new Forms of the same type.
But you don’t need a new instance. You’ve already got the instance you want: the “parent” form you mentioned. Anvil created it on demand, for displaying it. (Actually, it’s probably several “parents” removed. Call it an “ancestor”.) It’s live, on-screen, at the time.
The question then is, how to get the RowTemplate instances talking to that specific ancestor.
What I usually do, in this case, is create a custom event. This is a way to have the RowTemplate instance “call” upon a function in the ancestor Form, without having to actually go and find that Form. The function can receive whatever data the RowTemplate wishes to send.
Example (row template pushing datum line_item
back to parent):
def btn_contract_edit_click(self, **event_args):
"""This method is called when the button is clicked"""
self.parent.raise_event('x-edit-contract', line_item=self.item)
Example (parent form preparations to receive and act on that datum):
class Frame_ContractList(Frame_ContractListTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
self.repeating_panel_1.set_event_handler(
'x-edit-contract', self.on_edit_line_item)
...
def on_edit_line_item(self, line_item, **event_args):
cec = contract_editor_context.ContractEditorContext(line_item)
cec.invoke_editor()
Custom event names should begin with “x-”. Otherwise, name your event and your functions as you see fit, to help explain (to your later self) what’s going on.