What I am trying to do
I have an app that collects information from members of my fraternity group. The app has 2 forms:
Form1: collects personal data of each member
Form2: displays personal data extracted from a table in the server
After searching the table (say, keyword: gender = ‘female’), the data display in Form2. However, the data in the ItemTemplate mirrors that in Form1, i.e, all data items are in the ItemTemplate, but only the valid ones are filled (for textbox) or checked (checkbox). The gender data, however, are segregated in separate column panels as in:‘column_panel_female’; column_panel_male’.
What I want to do is display a cleaner Form2 through either of 2 methods:
-
Display an ItemTemplate in Form2 based on gender condition, or;
-
Use the default ItemTemplate but delete the column_panel (containers of male data) that is not needed since they are blank.
What I have tried but not working:
Method A:
Based on a test condition (gender), I tried to change the default ItemTemplate to one that I created for each gender as in:
if gender == "female":
self.repeating_panel_1.item_template = FemaleTemplate
Result:
It seems like the ItemTemplate created when instantiating a repeating panel cannot be changed at runtime. So, the above test failed.
It’s probably a dumb thing to do but I also tried to drop 2 repeating panels in Form 2, one for each gender, but it did not work either, again data display defaults to the ItemTemplate.
Method B:
I tried to apply the method that I found in this forum https://anvil.works/forum/t/manually-creating-and-adding-components/1299/5;solution by @David-Wylie as below:
myform = MyContentForm()
self.column_panel_contentpage.clear()
Replicating the above codes, I tried to delete the column_panel for male in the default (ItemTemplate1) since it componentis held there and can be clicked although without an event handler.
myform = ItemTemplate1()
self.column_panel_male.clear()
Result: I get error as: name ‘Itemtemplate1’ is not defined.
FWIW, I also tried putting the codes directly in Form2 but I get this error instead: AttributeError: ‘Form2’ object has no attribute ‘column_panel_male’ (more expected than not).
If Method 2 would would work, I prefer it over having 2 different ItemTemplates since I’d have less forms to create. All that I need to do is delete the unwanted column panels.
I have been experimenting hard to resolve it but just about out of wits to try.
How could I get around this problem?
Sorry for this long post.
Thank you very much.
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
Clone link:
share a copy of your app