I ended up with code that looks something like this where I first create a list of dictionaries & then iterate over the rows to compare values & add fields to Anvil.
Now I have a combination of static fields & dynamically created fields & I need to collect all of those values at once. Is there a global context that I can access?
for row in dataset_dict:
if dataset_dict.get('field_type', '') == 'button':
obj = Button(text=dataset_dict['Name'])
elif dataset_dict.get('field_type', '') == 'datetime':
obj = Datepicker()
#....
self.content_panel.add_component(obj)
You can loop through your content panel’s items using self.content_panel.get_components(). This will give you access to the components that you have added to that container. You can test for their types or store values on them that will help you identify them as you loop through (I usually store things on a tag property). For example, when you build your components, stick some data onto them, like:
obj.tag.name='something that lets me identify this component'
Or, you could similarly store your components, let’s say in a dictionary, and stick that dict on a tag property anywhere. Then you can look up the components by their associated key (that you specific when you fill the dictionary).