Persist state of form when navigating away from it

When I want to use the values used the last time the form was used as default, whether in this session on in the previous session, I do:

from anvil_extras.storage import local_storage

    def form_show(self, **event_args):
        year = local_storage.get('date picker year', 1999)

    def form_hide(self, **event_args):
        local_storage['date picker year'] = year

In my apps I rarely use the form_hide, I usually use the event that happens immediately after the value changes, this is just a quick example.


All my apps use the hash routing module. Often, when the value of a text box changes, I put all the values of the text boxes and other input components in url_dict, then I call:

    routing.set_url_hash(url_pattern='samepage', url_dict=url_dict, load_from_cache=False)

so not only is the current page updated, it is also possible to go back and forth in the browser history and it is possible to create a shortcut that includes the input as is at any point in time.

2 Likes