Reset st.text_input field

Before my form I use a lookup=st.text_input() field to look up whether a given name exists in the database.

How do I make it so that after the user enters the string in the text_input, the field is reset to empty?

if I do a search=’ ’ nothing happens

Hi @Edielcio_Almeida,

Thanks for sharing your question with the community! Check out our guidelines on how to post an effective question here and please edit your post to include a runnable code snippet

How do I make it so that after the user enters the string in the text_input, the field is reset to empty?

st.session_state.name = ""
st.text_input(label="Name", key="name")

and how to it only by press a special button not to by press enter or every change on streamlit?

You can make use of the value property, it would look something like this:

name_search = st.text_input(label="Enter a name to search", key="clean", value='')

# Check if user has entered a name
if lookup:
    # ...
    name_search = st.text_input("Enter a name to search", key="dirty", value='')

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.