Persist Dropdown list value between pages

Good afternoon,

I have a dropdown box in my header populated with the customers. The header is a reusable component and the dropdown box is its child.

The selected customer will dictate the context of the page. I need to be able to maintain the last selected customer even when I navigate between pages. Is this possible?

I’m new to Bubble and would be curious to know the answer as well. I don’t think Bubble’s custom states persist between page loads. In “conventional” web development, this would probably be stored in a “session variable”, but I’m not sure what the Bubble counterpart would be.

1 Like

Unless there is something about reusable components and/or dropdowns that prevent these, you should be able to either a) pass the customer in the url to the next page, or b) set a custom state of type customer on the destination page and pass the selected customer to it that way. Both of these options are covered extensively here in the forums.

1 Like

Thank you for the time in answering my questions. Option a) does not work as I have to capture the URL to set the default value of the dropdown box every time the page refreshes and that is not always possible.

Option B) is a no starter as I dont see how you can set a state on a destination page. State lifetime is equal to the lifetime of the page we are in and it is not transferrable across the session. If I am missing something please teach me.

You’re right that custom states do not pass between pages. Sorry, all my apps are single-page apps so I had forgotten that fact. Still, if it is an option for you to set the destination page to be of type customer, you could pass that to the page when navigating to it. If the current page customer can change and you want to keep the original one from page load, you could store it in a custom state when the page loads.

I have done this here as an example, though I’m not using a reusable component.

Custom states do not persist between page refreshes either, so that may well remain a problem for you. I don’t know how you would get around that other than to store it in the database.

I hope it helps.

Have you tried simply saving it with the user? Bubble does not expose “low level” concepts like sessions and cookies, but apparently saving data against the user object - logged in or not - should work. I have not tried it, but I’d be curious to know if it works for your situation.

I found the following posts informative…

Session variables
Do we have access to save cookies?

1 Like

That is very clever. Thank you for the suggestion

I have implemented this now and it is very elegant. It works perfectly. Thank you again.

This topic was automatically closed after 70 days. New replies are no longer allowed.