Session State Variables Not Saving Correctly Selectbox vs Multiselect

Hi @connorwatson0811,

Passing arguments with callbacks like this inside of a form is tricky. I would recommend avoiding using the callback to set the selected colleagues at all, and instead simply set a key on the selectbox or multiselect to automatically write it to st.session_state.

Here is an example that works, that I think has the desired behavior:

import streamlit as st

if "current_page_num" not in st.session_state:
    st.session_state["current_page_num"] = 0

if "selected_colleagues_form_1" not in st.session_state:
    st.session_state["selected_colleagues_form_1"] = None


def click_next():
    max_page = 3
    if st.session_state["current_page_num"] + 1 > max_page:
        st.session_state["current_page_num"] = 0
    else:
        st.session_state["current_page_num"] += 1


def click_prev():
    max_page = 3
    if st.session_state["current_page_num"] - 1 < 0:
        st.session_state["current_page_num"] = max_page
    else:
        st.session_state["current_page_num"] -= 1


def page0():
    st.session_state["current_page_num"] = 0
    if "input_name" in st.session_state:
        submit_colleagues = st.form("submit_colleages")
        with submit_colleagues:
            submit_colleagues.write("The following people work in your workplace:")
            all_colleages = [
                "Adam",
                "Betsy",
                "Colleen",
                "David",
                "Edward",
                "Fiona",
                "Gary",
                "Hasan",
                "Isabelle",
                "Jeremiah",
                "Kazuki",
            ]
            submit_colleagues.write(all_colleages)
            # st.selectbox works as expected
            # select_colleagues = st.selectbox(
            #    "Select Colleagues", options=all_colleages, key="selected_colleagues"
            # )

            # HELP - st.multiselect(), st.text_input() neither of these pass values to the next page
            st.multiselect(
                "Select Colleagues",
                options=all_colleages,
                key="selected_colleagues_form_1",
            )
            submit_colleagues.form_submit_button("Submit", on_click=click_next)


def page1():
    st.session_state["current_page_num"] = 1
    st.write(st.session_state["selected_colleagues_form_1"])


sidebar_form = st.sidebar.form("sidebar_form")
with sidebar_form:
    input_name = sidebar_form.text_input("What is your name?")
    input_name_submitted = sidebar_form.form_submit_button("Submit Name")

if input_name_submitted:
    st.session_state["input_name"] = input_name

display_next = (
    True if len(input_name) > 0 and "selected_colleagues" in st.session_state else False
)
display_prev = True if st.session_state["current_page_num"] > 1 else False

_, prev, next, _ = st.columns([5, 0.8, 0.8, 5])
if display_next and input_name_submitted:
    next.button(label="Next", on_click=click_next)
elif not display_next and input_name_submitted:
    next.button(label="Next", on_click=click_next, disabled=True)

if display_prev and input_name_submitted:
    prev.button(label="Prev", on_click=click_prev)
elif not display_prev and input_name_submitted:
    prev.button(label="Prev", on_click=click_prev, disabled=True)

pages = {0: page0, 1: page1}
pages[st.session_state["current_page_num"]]()