Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
nickgreengithub opened this issue Nov 1, 2024 · 2 comments
Open
2 tasks done

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

nickgreengithub opened this issue Nov 1, 2024 · 2 comments
Labels
feature:st.form type:enhancement Requests for feature enhancements or new features

Comments

@nickgreengithub
Copy link

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)

@nickgreengithub nickgreengithub added the type:enhancement Requests for feature enhancements or new features label Nov 1, 2024
Copy link

github-actions bot commented Nov 1, 2024

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

@jrieke
Copy link
Collaborator

jrieke commented Nov 1, 2024

Hey, it does work for st.number_input. I can see the point of having it work for other elements as well but they are definitely a bit less obvious UX since you don't really have a cursor/input field there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.form type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

2 participants