#7165·streamlit

Add form validation to make form fields required

Author: bararanCreated Aug 12, 2023Updated Sep 28, 2026
Labelstype:enhancementarea:widgetsfeature:st.form

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

Streamlit currently has no built-in form validation to prevent a form from being submitted when one or more of he required fields is not populated or has invalid data. Adding a manual check that gets executed on form submit button click is not ideal from a user experience point of view, because this means either the entire form will be cleared even when a required field is not correctly populated when the form's clear_on_submit property is set as True, or the form fields will still carry the entered values even when the form is successfully submitted if the form's clear_on_submit property is set as False.

Why?

If a form is submitted with all necessary fields populated, ideally I would want the form to be cleared upon submission and hence would want clear_on_submit set to True. When, however, a necessary field is left empty I would indeed want the already populated fields to retain the provided input rather than being cleared.

I could not make things work with a form but wrote a workaround that does not use a form as follows: I created input fields (not inside a form), created state vars assigned to keys of input fields, added a standard button, created a function to reset the state variables to be called from within the on_click function of the button only when all compulsory fields are populated.

However, I do think this is way too much work for a simple form validation, which is pretty fundamental feature built into any web framework that I’ve ever worked with (I do recognise that Streamlit probably does not aim to become an all-purpose web framework but still), and in my humble opinion, make it difficult for Streamlit to be adopted by a wider user base.

How?

Adding a required property to form input fields might be a possible solution.

Additional Context

This issue was discussed at https://discuss.streamlit.io/t/make-input-fields-required-using-st-form/30822