how to disable text input after user finish input?
now use disabled=True will make input unavailable before user input something.
Thank you.
Anyone have solution for this requirement?
Thank you.
Sorry, your question is not clear to me.
Am I understanding correctly:
a) Your have a text input widget
b) once the user enters something in the input then you want the text input widget to disappear?
My suggestion is this
- Make an empty widget with st.empty
- In the empty widget you just made, create an st.form
- In the form you just made, include a st.text_input widget where the user can enter text.
- In the form you made, you have to include a button. When the button become “submitted” turn your form back into a nice message using something like st.write
So the basic idea is you go from
mywidget = st.empty → (mywidget = st.form + st.text.input) → mywidget = st.write
Does that make sense?
Here’s an alternative to using forms and st.empty:
Solution
import streamlit as st
if "disabled" not in st.session_state:
st.session_state["disabled"] = False
def disable():
st.session_state["disabled"] = True
st.text_input(
"Enter some text",
disabled=st.session_state.disabled,
on_change=disable
)
Output
Best,
Snehan
Thank you very much.
Thank you! But is there a way of, except for re-loading the site, to enable the text again?
You can manually set st.session_state["disabled"] = False
somewhere in your code, or define an enable
function if you want to set it as a callback to some other action.
def enable():
st.session_state["disabled"] = False
Thank you a lot for your very good - and fast response!
Hi @mathcatsand
I set st.session_state.disabled to False in the last line of my script. However, the text widget is still disbaled. Can you give some hints?
If you’ve set it to False
at the end of your script, then anything prior would not see that new value. Whatever value your widget function sees in its disabled
parameter (at the moment the widget function is executed) is all that it will know. The value in session state would need to be False
before passing that value to your widget on your last rerun.
Thanks for your reply. I solved my problem by calling experimental_rerun
in the end, such that the input area can be re-enabled automatically.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.