Submit button on Enter key press

I need extra functionality in my app, whenever user hits enter key on keyboard, the submit button functionality should run (Which now runs when user clicks with a mouse). Any help is appreciated. Thanks.

Hi @deepanshu_dey ,

Welcome to the Streamlit community forum :partying_face: :balloon:

A use case would have been ideal to understand the issue.
However, if you need your app to run on press of Enter key, you can use st.text_input widget.

Does this help ?

*Best , *
Avra

I have a button inside a form.

with st.form(‘user_form’, clear_on_submit = True):
msg = st.text_area("Message: ", value = “”)
submit_button = st.form_submit_button(label=“Send”)

This button functionality is written in this way:

if submit_button:
Code functionality

Problem is whenever I will hit enter key, submit_button should run…

I have this same request. Inside of a form, the enter button should execute the submit button code. This is normal behavior for HTML forms. The suggested fix works outside of a streamlit form, but not inside of it.

Web is not my thing, and I’m not the best person to answer that, but from what I understand, if you’re inserting or changing a text inside an input, it wouldn’t be appropriate to trigger the submit since Streamlit doesn’t know if you finished the process.

Perhaps this would be possible if the input being edited was the last one on the form.

A feature request for that was added a year ago: