First of all, this is related to Add slots inside designer-placed components in HTMLComponent
I’ve been experimenting with using a form as both layout and custom component.
Since it’s a weird situation, I’m start by giving names:
- There’s the basic form, that is now a layout. I’ll call that BaseLayout (BL);
- I made a form that uses BL as it’s layout. This form is also a CustomComponent. I’ll call it LayoutComponent (LC);
- There’s another form, that uses another layout and has LC as a component that was added using the designer. I’ll call it NormalForm (NF).
The BaseLayout has a property called mode
, which is of type Enum and has two values: INIT and CONFIG. The default is CONFIG.
The LayoutComponent also has a property called internal_mode
, which behaves exactly the same as BL, with the only difference is that it’s default value is INIT.
In LayoutComponent, the layout.mode
is binded to self.internal_mode
in a way that if another usage of LayoutComponent as a component changes the default value, it should also propagate to BaseLayout.
NormalForm has layout_component_1.internal_mode
statically set as CONFIG
in the designer.
Expected behaviour
When I open LayoutComponent as a form, it should use the default configurations: INIT for itself and propagate INIT for the layout. Also, I expected that LayoutComponent’s __init__
method started before, then BaseLayout’s __init__
would be called in LayoutComponent.init_components(**properties)
. All of this was true for the first part.
I also expected that when I opened NormalForm, it should pass the CONFIG parameter to LayoutComponent, which would then pass to it’s layout and would all work well. This was not what happened.
What happened
When opening NormalForm, BaseLayout should be setup with CONFIG
as it’s mode
, but this wasn’t the case. I put a few prints, before and after each of the self.init_components(**properties)
of the components to see the behaviour.
This was the output for opening LayoutComponent as a form:
LayoutComponent before init_components. internal_mode: INIT properties: {'routing_context': <routing.router._context.RoutingContext object>, 'internal_mode': 'INIT'}
BaseLayout before init_components. mode: CONFIG properties: {'__ignore_property_exceptions': True, 'mode': 'INIT'}
BaseLayout AFTER init_components
LayoutComponent AFTER init_components
The the component started, than it’s layout started and the properties were correctly sent as expected.
However, the output for opening NormalForm was:
LayoutComponent before init_components. internal_mode: INIT properties: {'__ignore_property_exceptions': True, 'internal_mode': 'CONFIG'}
BaseLayout before init_components. mode: CONFIG properties: {'__ignore_property_exceptions': True, 'mode': 'INIT'}
BaseLayout AFTER init_components
LayoutComponent AFTER init_components
NormalForm before init_components
NormalForm AFTER init_components
NormalForm was initialized AFTER the component inside of it. Also, LayoutComponent correctly received internal_mode: CONFIG
in it’s property. However, BaseLayout DIDN’T receive mode: CONFIG
, even though it’s binded in the layout.
Another thing that I observed it’s that sometimes this order was changed if I used self.layout
before init_components
.
I don’t really understand why. I think I’m navigating uncharted territory and it’s making me really confused.
If anyone can help me with that…