How to access parent form class variable

I have a class variable in parent form. How can I access it from repeating panel RowTemplate. I though I can access it using get_open_form() but didn’t find much info about it in documentation.

Hello,

You could search the forum and docs for any info on repeating panel templates and accessing their parents, also look for how to pass variables between forms, and tags.

There’s also helpful info in this post about reaching around to access variables and forms. There are lots of linked posts there too that may contain issues similar to yours.

I hope this helps in some way

Have you tried importing the parent form and instantiating it…and then access the variables within the form instance

It all depends on the heirarchy of your forms.

- Form1
   - RepeatingPanel
      - ItemTemplate

Where does your class variable live in relation to the heirarchy? Is it Form1?
Is Form1 the open form?
If yes then you should be able to do

get_open_form().my_variable

You could access it via parents

# from the item template
self.parent.parent.my_variable

I would try to avoid using too many parents though - if you get to 3 parents then there’s a better way. Even with 2 parents I’d think twice.
(I avoid multiple parents because if you later decide you need a card component within this hierarchy well then your line of parents is now all wrong!)

You could also pass the Form1 instance to the item templates in some fashion. Since Form1 is an object you can pass it around as you like.

If you need more it would be useful to see more code snippets.

3 Likes

What would be a possibility to pass the Form1 object to a repeating panel RowTemplate? Not as an item of the Row Template form. But what else?

One idea - you could provide an item template to the repeating panel that is a function.

from .ItemTemplate1 import ItemTemplate1 as RealTemplate

class Form1(Form1Template):
    def __init__(self, **properties):
        ...
        def ItemTemplate(**properties):
            item_template_row = RealTemplate(**properties)
            item_template_row.caller = self
            return item_template_row

        self.repeating_panel_1.item_template = ItemTemplate
        # we can set the item_template to a function that returns a component

Inspired by the answer to this question:

Thanks, for this is food for thought.