Children to Parent Update

Hi guys!
I’m kinda stuck in my own design and I need your help! :slight_smile:

Here’s what I have:

The homepage have links that lead to another page with a period value, self.item passing to the other page. On the other page, I used a repeating panel to list bills with amount depending on the period value. These bills also have a delete link. When I use the delete link, it works great. The only problem I have, is the label with the total of the bills. I cant find a way to update the label when the delete link is hit, since the repeating panel is a child to the parent. Perhaps my whole approach is wrong.

The question :

Is it possible for me to trigger a function or some kind of update from the child to the parent?

PS : I would love the know how you are doing this king of stuff in your projects! I mean how to deal with aggregate (total) and list of rows (repeating panel).

Thanks a lot!

This link will help

Events work well, as described in Tony’s link. I specifically put the event handler on the repeating panel so that the row items can call self.parent.raise_event.

It’s described in my personal cheat sheet of practices: https://github.com/jshaffstall/anvil-practices/blob/master/data-grids.md#triggering-events-in-data-grid-rows-that-call-form-functions

1 Like

Thank you very much guys!
I think, I am very close!

I now get the ‘NoneType object has no attribute raise_event’
Just like you describe on your github page.

The event listener is on the form with the function to call.
The parent.raise_event is on the repeating panel erase link.

So :

Bills Form

 Init -> self.pnl_bills.set_event_handler('x-update-labels', self.update_labels)

 def update_labels(self, arg):
      ...

Repeating Panel (as ItemTemplate)

 def link_1_click(self, **event_args):
       ...
       self.parent.raise_event('x-update-labels', arg=arg)

try checking what self.parent is using print
did you just before call self.remove_from_parent()
if yes… then it no longer has a parent.

you can store the parent before you remove it…

def link_1_click(self, **event_args):
       parent = self.parent # still  on the screen
       self.remove_from_parent()
       parent.raise_event('x-update-labels', arg=arg)

worth being cautious with this approach - if you change the components but don’t adjust repeating_panel.items you may wind up with a reappearing item. Since your UI no longer matches…

It may be worth cleaning up the items.

3 Likes

Hi guys!

I know its been a long time but life happened! :slight_smile:
Everything is working fine now in the app now!

Thanks for your help!
Have a good one!

1 Like

What is a good way to cleanup the repeating_panel.items that the user removes. Say you have a ToDo list and you want to remove the item somewhere in the middle of the list. As you said, just doing self.remove_from_parent() will only remove the item from view but not update your list if another function retriggers the repeating_panel to reshow the items.

My use case does not have a database, the data is simply cached in a python list, so updating a database as this tutorial (Storing and Displaying Data with Anvil - YouTube) shows would not work for me.

The original question, under the original title, has been answered. Recommend that you start a new question, with a suitable title, so that people can see it and know that it has not been answered yet.

1 Like