What I’m trying to do:
I have a parent form where I would like the UI to change when user presses the delete in a repeating panel. The UI is suppose to delete the row, and refresh the repeating panel.
What I’ve tried and what’s not working:
Parent
class Admin_page(Admin_pageTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Listen for the update event from repeating panel rows
self.repeating_panel_users.set_event_handler('x-update_status', self.refresh_data)
# Set initial data
self.refresh_data()
def refresh_data(self, **event_args):
"""Refreshes the repeating panel's data."""
self.repeating_panel_users.items = app_tables.onboard.search()
def button_save_click(self, **event_args):
"""This method is called when the save button is clicked."""
anvil.server.call('save_new_client', self.text_box_email.text, self.dropdown_menu_type.selected_value)
self.refresh_data() # Refresh the panel after adding a new client
Child
class Users(UsersTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.set_event_handler("x-update_status", self.refresh_data)
self.text_email.text = self.item['email']
self.dropdown_menu_user_type.selected_value = self.item['type_of_business']
# Any code you write here will run before the form opens.
def dropdown_menu_user_type_change(self, **event_args):
"""This method is called when an item is selected"""
new_status = self.dropdown_menu_user_type.selected_value
if self.item['type_of_business'] != new_status:
self.item['type_of_business'] = new_status
try:
anvil.server.call('update_lead_status',self.item['id'],new_status)
self.raise_event('x-update_status')
except Exception as e:
alert(f"Error saving status: {e}")
print(self.item['_key'])
pass
def refresh_data(self, **event_args):
self.refresh_data_bindings()
def button_delete_click(self, **event_args):
"""This method is called when the component is clicked."""
# Confirm deletion
if not confirm("Are you sure you want to delete this user?"):
return
try:
# Remove from the database
anvil.server.call('delete_user', self.item['email'])
# Notify the parent form to refresh the list
self.raise_event('x-update_status')
except Exception as e:
alert(f"Error deleting user: {e}")
pass
The row gets deleted, but… UI stays the same. I have to restart the app to see changes. How do you make it refresh after an event click on the “Delete Button”
Clone link:
share a copy of your app