St.selectbox does not work in st.form

It seems st.selectbox doesn’t work inside st.form since no changes happen until submit button is clicked.

Is there any workaround?

Sudipta Bhawmik

Hey Sudipta, thanks for your question! You’re absolutely right—when you put an st.selectbox (or any widget) inside an st.form, its value won’t update or trigger a rerun until the form is submitted. This is by design: forms batch all input changes and only send them to the backend when the user clicks the submit button. So, you can’t get immediate UI updates or dynamic behavior from widgets inside a form until submission, and this limitation is documented in the Streamlit docs.

If you need widgets to update each other or the UI immediately (for example, a selectbox whose choice changes other widgets), you should place those widgets outside the form, or use st.container instead of st.form. Alternatively, you can use st.empty placeholders to position widgets outside the form but visually group them together, as discussed in this forum thread. There is no built-in workaround to make widgets inside a form update before submission.

Sources: