Issues with st.date_input validation

Hi,

Streamlit, version 1.45.0

I am running into an issue with how st.date_input works.

I have set it so that there is a max date of 90 days as the selectable range, however a user is still able to manually input a range outside of this scope. This forces an error message on the Frontend side it seems, which shows the input in Red saying its wrong. It doesn’t however stop the user from continuing, a user can still click on my “Submit” button with the date input beeing “wrong” or not valid.

The actual date that the user would send in would be the last set value before the “wrong” one, but the user wouldn’t know that.

How can I for example, make it so that the Submit button wont show up when the validation check only seems to be happening in the frontend? I cant check to see if st.date_input has a value, cause it would have one, just not the one shown in the frontend.

I could reproduce the issue:

import streamlit as st

d = st.date_input(
    "Enter a date in 2024:",
    value="2024-01-01",
    min_value="2024-01-01",
    max_value="2024-12-31",
)

submit = st.button("Submit", disabled=d.year != 2024)

if submit:
    f"You made it, you entered **{d}**!"

The expectation is that the button is disabled because the date is outside the range. But the widget won’t send the invalid date back to the server and a rerun is not triggered. As far as I can tell, this behavior is the same with other input widgets. The easiest workaround is to ignore the min_date and max_date arguments in st.date_input and do the value validation on the Python side.


Not sure how that could be enhanced from Streamlit because this is a general pattern with inputs in HTML. See the first example over <input type="date"> - HTML: HyperText Markup Language | MDN. The max and min bounds are used to modify the widget interface so only valid dates can be selected, but the user can still write an invalid date with the keyboard. More details in the validation section.

Would it be possible to maybe add an option to st.date_input that makes it so the user can’t manually add in input? So they can only use the date selector.