Hey,
I have noticed that a form with multiple submit buttons is not working if one of the buttons is disabled. The button that should be enabled does not trigger.
I have also opened up a GitHub issue: Form not submitting if there are multiple submit buttons and one of them is disabled · Issue #8075 · streamlit/streamlit · GitHub
Here is my “demo code” to reproduce it:
import streamlit as st
with st.form(key="my-form"):
st.write("1 Disabled button, 1 Enabled button")
text_input = st.text_input("Text input")
disabled_btn = st.form_submit_button("Disabled Button", disabled=True)
enabled_btn = st.form_submit_button("Enabled Button", disabled=False)
if disabled_btn:
st.write("Disabled button clicked")
st.write(text_input)
if enabled_btn:
st.write("Enabled button clicked")
st.write(text_input)
with st.form(key="my-form2"):
st.write("2 Enabled buttons")
text_input = st.text_input("Text input")
first_btn = st.form_submit_button("1. Enabled Button", disabled=False)
second_btn = st.form_submit_button("2. Enabled Button", disabled=False)
if first_btn:
st.write("Disabled button clicked")
st.write(text_input)
if second_btn:
st.write("Enabled button clicked")
st.write(text_input)
Best regards
Tian