How to send a return value from an alert containing custom component?

I am feeling the Anvil :heart: and having lots of fun. However, I can’t figure out how to do the following:

I have created a custom component which includes buttons. I’ve gotten my event handlers all hooked up and assigned so that when a button is pressed I can raise the appropriate event on the form that contains the component.

What I really want is to use alert(contents = my_component, buttons = []) and then get back which button was pressed.

I can’t figure out how to return this value, nor how to get ride of the alert box after the component button is pressed. The component oddly says it doesn’t have a parent, neither the alert, nor the form that called the alert.

Please help!

Assuming I’ve understood your issue correctly -

If you call the alert box like this :

selected_value = alert(...)

when you raise the x-close-alert event, you pass a parameter value :

self.raise_event("x-close-alert", value="ret_val")

This closes the alert box and returns the value to the calling form.

3 Likes

Welcome back!

If you look at the example in
https://anvil.works/docs/client/python/alerts-and-notifications#custom-popup-styles
you’ll see how buttons, if used, provides you with both buttons and return values.

Is there a reason that this method wouldn’t work for you?

1 Like

Works! Thanks @david.wylie @p.colbert for all the help (checks notes) showing me the part of the documentation I missed even though I’ve been reading it all morning!

1 Like