Allow st.form enter_to_submit to work for non-text elements

Open
#9,761 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
frontend

Research direction

Start with the provided st.form(..., enter_to_submit=True) example and reproduce the behavior for radio, dataframe, number_input, selectbox, and text_input alongside st.form_submit_button. Done means Enter submits the form consistently for supported non-text elements without regressing text input behavior.

Written by the indexing model from the issue text.

Description

feature:st.form type:enhancement
Checklist
  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.
Summary

I found that enter to submit only works for text entry elements - it doesn't work for:

  • radio selections
  • dataframe selections
  • number inputs
  • presumably others (selectbox etc.)
Why?

When I test my own forms, which rely on the st.dataframe row selection feature, intuitively I select and press Enter (Return) and expect the form to submit.

Limiting this only to text reduces the usefulness of forms, quite a lot for me

How?

however the text input works -- repeat for all input elements!

Squeezing in the 'Enter to submit' message probably isn't possible, but that's okay.

Additional Context

import streamlit as st
import pandas as pd

test_number = 0

with st.form(key='form_select_step',enter_to_submit=True):

a1,a2,a3,a4 = st.columns([25,25,25,25])

test_radio = a1.radio('radio',['test1','test2','test3'],index=0)

test_dataframe = pd.DataFrame({'test':[1,2,3]})
a2.write('dataframe')
test_dataframe_selection = a2.dataframe(test_dataframe,on_select='rerun',selection_mode='single-row')

test_number = a3.number_input('number',value=10)
test_string = a4.text_input('string',value='test')

st.form_submit_button('form submit')

a1,a2,a3,a4 = st.columns([25,25,25,25])

a1.write('Test Radio:')
a1.write(test_radio)

a2.write('Test Dataframe Selection:')
a2.write(test_dataframe_selection)

a3.write('Test Number:')
a3.write(test_number)

a4.write('Test String:')
a4.write(test_string)

Dominant language
Python
Stars
45.8k
Forks
4.4k
Avg merge
21h 22m
Merged PRs (30d)
316

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from streamlit/streamlit

All issues in streamlit/streamlit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.