Returning to an already initialized form

I apologize if this question has already been answered, but I have not been able to find anything. Here is my problem:

What I’m trying to do:
I have a web-app with multiple forms, say; Form1, Form2, …, FormN. And a navigation bar where a user can select which form they want to access.

When a user goes from Form1 (the startup form) to FormN, I would like the user to be able to return to Form1 without the init method of the form being called. i.e Once Form1 has been created for user x, I want form1 to retain the data and not re-initialize.

I would like this to be done for every form, such that the user can navigate between forms without needing to re-enter information.

What I’ve tried and what’s not working:

Currently, to access a form I have a navigation bar with a “link” component that on click, calls the open_form() function (see below):

def link_form2_click(self, **event_args):
    """This method is called when the link is clicked"""
    open_form('Form2')

Per the docs this does not work as open_form(‘FormN’) creates a new instance.
I have also tried:

form2 = Form2(parameters='my_parameter')
open_form(form2)

But I am unable to return to my startup form without receiving the “circular import” error.

If I need to setup my anvil app in a different manor, I am willing to make any necessary changes to accommodate for this feature.

If I need to provide more details, please let me know. Thanks.

There are many way to do that. The one I use and strongly advice, because it comes with plenty of other advantages, is using the routing module from Anvil Extras. You will need to use the url to navigate to a form instead of the usual Anvil way.

2 Likes

Thanks for the recommendation. I will check it out!