If I change values of some widgets in a dialog, next close it by pressing “X” or clicking anywhere on screen and open it again I see widgets with edited values.
How to prevent streamlint dialog from keeping changed values in such case?
Looks like it could be possible by ss.rerun() in “X” / clicking anywhere event handler but there is not such event.
You can add keys to the widgets and set them to a default value before creating them:
import streamlit as st
@st.dialog("A dialog")
def show_dialog():
st.session_state.dialog_text = ""
st.text_input("Say something", key="dialog_text")
if st.button("Show dialog"):
show_dialog()
As you add more widgets this can become inconvenient, I guess you could use a form with clear_on_submit=True
in that case (not tested).