Determine which button triggered the pop-up

Hello everyone.
I have 3 buttons A, B, and C. when any button is pressed a pop-up will appear. for the 3 buttons, I need the same UI so I’m using one pop-up element—however, the data changes based on the button.
My problem is how would I know which button was pressed to send the type of button to my external database. filter the data based on the button pressed and then send that data to the pop-up to show it.

What I did was I created a database on bubble. in the workflow of each button, I insert the piece of information I need onto the database. by that, I know which button triggered the pop-up.
when the pop-up is closed. I delete the saved data on bubble database.
tho this is not efficient at all for saving a piece of text that I only need to tell which button triggered the pop-up.

Is there any other way to achieve this!

Hi there, @dev50… there is definitely a better way to do what you described, and that better way is to use a custom state. When the buttons are clicked, set a custom state to a particular value, and use that value in conditionals on elements and/or in workflows to show the appropriate data in the popup. Then, when the popup is closed, clear the custom state, and you’re good to go.

Hope this helps.

Best…
Mike

1 Like

Hi @mikeloc, Thank you for your reply
I tested it and indeed it does exactly what I need. but I have questions.
Do I think of custom states as a global variable! cuz if I were to implement that using any programming language the easiest way to do is to have a global variable for it.
How can I access and view the saved custom data? for DB values it’s accessible in the Data tab.
How can I remove the custom state when the pop-up is closed?

I won’t do a better job of describing custom states than Bubble themselves, so check this out.

With regard to how you view the data a custom state is holding, well, you can’t. Okay, you can, but not like you do with stored data on the App data tab. You would have to put an element somewhere on a page that displays the custom state’s value.

To remove the value in a custom state when the popup is closed, add an action to the workflow event that closes the popup, and have that action remove the value from the custom state (i.e., set the custom state to blank). If you don’t have an explicit workflow event that closes the popup, use the A popup is closed workflow event, and add the aforementioned action to that event.

1 Like

I just watched that video. true it’s so informative. I removed the custom state aka assigned a blank value. and now it works like a charm

again thank you so much for ur help.

1 Like