What I’m trying to do:
Drag components into an empty slot on a form that acts as a layout
What I’ve tried and what’s not working:
- I’ve made a form and set it as a layout.
- Within that form (not a form using it as a layout), try to drag a component into the empty slot – it never drops within the slot, only to any side of it.
If I use self.slots["slot_name"].add_components(Component())
to add a component within the layout form it works.
Clone link:
share a copy of your app
In the clone above, if you try to drag a component into the empty slot in the layout itself, it won’t work, but if you do it in InheritsLayout there’s no problem.
This seems like a bug since you can add components to the slots programatically but not with the designer.
This is intended behaviour, and it’s not recommended for layouts to put components inside their own slots.
It should really be up to the Form using the layout to decide what to put inside slots.
The layout should effectively relinquish control over its slots.
“Here’s places you can put whatever you like, whenever you like… I won’t touch these, I promise”
If the layout you’re creating always needs a Button, it shouldn’t go in a slot. It should instead be integrated directly into the layout.
Something you’ll run into with your code snippet:
2 forms can reuse the same layout.
This can happen with open_form()
, for example
Let’s say Form1
and Form2
both share Layout1
If Form1
is on the page, and we do open_form('Form2')
Anvil will recognise that they have the same layout.
Anvil will clear the slots of Layout1
and Form2
will now add its components to the slots of the Layout1
instance.
In this scenario, if Layout1
had dynamically added a component to its slot, this component would be lost.
here’s a clone link that demonstrates the situation above: