Form elements can't get new values

Environment: Mac/M1, chrome, streamlit 0.85.1

with st.form(key="update_status"):
            selected_code = st.selectbox('select code', df["code"].tolist())
            selected_status = st.selectbox('select status', status)
            btn = st.form_submit_button('submit')
            print(btn)
            if not btn:
                submit_status(selected_code, selected_status)

I found two issues not complied with the document:

  1. if I use “on_click” to call submit function, two select values can’t be updated
  2. if I use return value of submit button to call it, return bool value is oppsite to common sense. Only like my code, the evnent to click button can be invoked.

I don’t understand how to create a form in streamlit acting like other web forms. Is it because of document or bugs in code?

1 Like

Hi @winglight welcome to streamlit!

I think you can update the two values with onclick= callback. Additionally pass along those variables with args=

with st.form(key="update_status"):
            selected_code = st.selectbox('select code', df["code"].tolist())
            selected_status = st.selectbox('select status', status)
            st.form_submit_button(label='submit', onclick=submit_status, args=(selected_code, selected_status))

I’m not sure how to address the reverse-logic you’re mentioning… does this help?

Thanks joe. I tried the way you mentioned that caused the same result. But I did find out why just now.

There’s a button to load the whole UI manually in the code. When I move this function to the root of code that resolves the problems above. I guess streamlit using “reload the whole page” to pass params to submit function. This design idea blows my mind. :man_shrugging:

1 Like

Glad you could resolve it!

On the same boat, trying to figure out how things work :grinning: See if you can help me here: How to create recurring forms with unique keys?

I saw your post before, but I don’t recomend you to take time on it. IMHO, streamlit is only appropriate to the single page for ML charting and it’ll reload the whole page on any trivia change. It’s better for you to find another solution even Google Docs.

1 Like