Skip to content

response_mode blur and preset text #33

@palomena

Description

@palomena

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions