Layouts sound like a really powerful feature. However, I have not gotten over the initial “how do I use this?” learning curve.
What I’m trying to do:
I’m mainly hung up on how to share state between the Layout Form, the Form using the Layout (we’ll call it the “Main Form”), and the “SubForms” using the slots.
My general use-case is going to be to load a Form with an entity (maybe an anvil row, or a portable class), and each of these SubForms will be responsible for showing the user some aspect of that.
It feels like each SubForm should take the entity as an argument, but, it’s not clear to me when/how the Form should propagate that through. We could instantiate them in code and insert them into slots in the Main Form __init__
but that doesn’t feel very Anvil-y (not at all WYSIWYG).
Alternatively, should my SubForms somehow retrieve the entity from the Main Form? Sub Form get data from the Main Form (or is that discouraged)?
What if we wanted to add logic to the Layout Form? I can imagine there being common methods we want to add there, to be used by different Main Forms sharing the Layout Form. How do I get the Layout Form instance form my Main Form? From my SubForms? I see that MainForm
has a layout
attribute - is that available from SubForm
? Am I right in assuming that’s what layout
is for?
Edited to add: The tutorial talks about using open_form
, but we are using routing
, so I’m not sure if that’s relevant or not.
What I’ve tried and what’s not working:
I see that Forms dropped into a Slot have a item
binding, so I tried binding to that, but, that is not available when the SubForms are actually instantiated.
See this clone link (that is not at all working, but is meant to show how I thought it might be supposed to work):
This includes a Layout that is meant to show a User
details, so it includes layout that includes a User Header (to show the user details) and a User Comments (which accesses a user’s comments, through a multiple row relationship).