Forms - form_submit_button in sidebar

Hi Guys,

Thank you for adding forms to the streamlit. It is not quite I wanted but it is getting close.

I was wondering if there is a way that the submit button of a form places in the sidebar.

here is what I’m looking for:

with st.form(key='my_form'):
	text_input = st.text_input(label='Enter some text')
	submit_button = st.sidebar.form_submit_button(label='Submit')

But it gives me an error since the button will be in the sidebar scope not in the form scope!

1 Like

I Had same issue a few days ago, this is solved by creating a bigger scope, like this:
Notice that the st.form.submit is not in a st.sidebar, due to it already being a part of the block of sidebar

with st.sidebar:
      with st.form(key='my_form'):
    	    text_input = st.text_input(label='Enter some text')
    	    submit_button = st.form_submit_button(label='Submit')
1 Like

Thank you for your reply. This makes the form to be in the sidebar.
visually what I’m looking for is that only the submit button appears on the sidebar and form itself on the body of the website

I think after a bit of thought of what you did I could do it.

However there is one strange behavior (might be bug?)


with st.form(key='my_form'):
    text_input = st.text_input(label='Enter some text')
    st.sidebar.checkbox('checkbox',False)
    with st.sidebar:
        submit_button = st.form_submit_button(label='Submit')

and


with st.form(key='my_form'):
    text_input = st.text_input(label='Enter some text')
    with st.sidebar:
        st.checkbox('checkbox',False)
        submit_button = st.form_submit_button(label='Submit')

There shouldn’t be any difference between these two!
Both are wrapped in a form, however interacting with the checkbox in the first one will result in refreshing the page! Any insights?