some thoughts:
key principle: your form won’t be displayed until __init__
has executed.
__init__
everything in __init__
wil run and then the form will be displayed/loaded to the screen.
(assuming that it is either the main form open_form('Form1')
or it has a visible parent self.content_panel.add_component(Form1())
- if your form needs
data
withdata bindings
when it is visible put these in your__init__
method - calling
open_form
inside an__init__
method will fail- the other form’s init method will execute, but the current form will be displayed afterwards.
- calling
self.call_js
will fail- the form has yet to load (but
anvil.js.call_js
will work for any js function that is already loaded)
- the form has yet to load (but
- timer events only start after
__init__
and only when the form is on the screen - if you have a lot of data to load consider moving this out of
__init__
- instead get some data that is quick to load,
- start a background task
- check the background task state with a timer event.
form_show
this event is triggered after the __init__
method has executed, and when the form has been loaded onto the screen.
It is also triggered whenever a form reappears, or whenever you do self.visible = True
- put
self.call_js
here - if you
cache
your forms (likeHashRouting
does) use theform_show
event when a formreappears