Closing an alert programmatically?

Dear Forum members

I am stuck building a website which aims to display some research data. I have an alert that displays a form containing buttons and related images. When a button is clicked it displays the related image in an image box on the main page. I want this click event to also trigger closing the alert. Is this possible?

This is what I have tried and is part of the code for the form that is shown in the alert:

def handle_click(self, **event_args):
        # Get the species name from the text of the button that was clicked
        clicked_species = event_args['sender'].text

        # Raise the event
        self.raise_event('x-species-clicked', species=clicked_species)
        
        # Close the alert
        anvil.alert.close(clicked_species, dismissible=true)

Many thanks

S

The docs show closing an alert programmatically: Anvil Docs | Alerts and Notifications

1 Like

Brilliant! I had not understood the docs, but your guidance has led me to a solution replacing the last line of my code with:

self.raise_event(‘x-close-alert’, value=clicked_species)

Thanks again, you have helped me previously and I am inching towards a working website that I can publish for the conservation community and which I will also share with the Anvil Community… very soon.

S

1 Like