response_mode blur and preset text
Hello!
The argument response_mode="blur" appears to be designed to enable interfacing with external buttons. It works when I type something into the code editor and press the button - I get a dict with the contents I've typed. Unfortunately, when one uses a preset for the text inside the code editor and a user presses the button without prior interaction with the editor widget, the returned dict is empty. Only after the user interacts with the code editor in some way does the response take on the appropriate value (even if the user simply clicks inside the editor).
Would it be possible to accomodate for the situation where a user only clicks the submit button without prior interaction with the editor itself? I provide sample snippets and most users try them out before making any modifications, which results in an error.
Minimal test case:
import streamlit as st
with st.form("editor", border=True):
DEFAULT_TEXT = "Hello World!"
response_dict = code_editor(DEFAULT_TEXT, "sparql", allow_reset=True, key="sparql-editor", response_mode="blur")
if st.form_submit_button("Query"):
print(response_dict)
Result:
{'id': '', 'type': '', 'lang': '', 'text': '', 'selected': '', 'cursor': ''} # without interaction
{'id': 'c85cb290', 'type': 'blur', 'lang': 'sparql', 'text': 'Hello World!', 'selected': '', 'cursor': {'row': 0, 'column': 12}} # after clicking inside the editor widget
I see what you mean. Essentially, the default return object should reflect the editor and its content even at the start. I think this should be easy to fix and I am currently working on it.
If you want the code editor to always update the response object when new stuff/variables is passed in to the code_editor function (regardless of interaction), that will likely require a new response mode or feature.
In the meanwhile, I suggest using the blank id string as a way to detect this situation and just use the code you pass in this case.
Is response_mode meant to be used by end-users? How come it doesn't show up on the reference page?
Hi. The docs are in need of a serious update. I am working on rewriting it and fixing issues. Its taking some time though and I don't have much free time these days due to how busy I am with other things.
Hopefully, Ill get the update finished this month!
To answer your question, yes, response_mode is one of a few new parameters and changes that are not shown in the docs yet. I apologize for the confusion. I gave a breakdown of how to use it in this Streamlit forums thread where I first announced/shared this component.