Hi guys,
I looking for a way to pass custom properties from the parent form to a child form. I read the docs (
https://anvil.works/docs/client/custom-components) but it is not clear to my how the initialization works in detail. I was kind of assuming that the custom property is handed downward within the kwargs (**properties) of self.init_components, but this seems not to be the case.
So how can I achieve this?
some good examples in the library
Slider would be a good one to start with
Thanks @stu, but this explains just custom getters and setters. My case corresponds to the Main Form being a custom component with one custom property which I would like to pass down to the slider component.
Like
raise_event_on_children
cascades the event down the children tree, there must be a similar mechanism when the forms initialise.
A clone or more pseudo code that you would hope to work might be useful here.
init_components
sets the item
, initialises any data bindings
and sorts out your @properties
if you’ve created any.
raise_event_on_children
could be useful but it would only go 1 level and would need to use set_event_handler
to catch the event.
You could also iterate through components of a form either using form.get_components
or by going through its dir
with
for component_name in dir(self):
component = getattr(self, component_name)
if isinstance(component, Component):
# do somethings
1 Like
Thanks a lot @stucork,
that’s pretty much what I was looking for!