Time input refreshes and overwrites my manual input

Hi all - thanks for taking the time to answer:)

I added st.date_input() & st.time_input() for my view.
My problem is, that most of the times when i want to manually input a date, streamlit adds the default value to the view and it loses my already filtered stuff. That’s rly annoying and bad UX. Is there any way i can turn off the auto-reload?

Currently i’m inputting the data. (then the page reloads) then i input the data quickly again and that’s annoying because i want to keep the same time filters, but for example change the Strategy

image

Can you provide a code snippet? It looks like you are using a form and the default is clear_on_submit = False so it should retain the values of the last submission if you haven’t set that optional keyword.

with st.sidebar:
    with st.form("my_form"):
          time_filter = datetime.now() - timedelta(days=2)          
          
          st.write('View Period')
          col1, col2 = st.columns(2)
          with col1:
              date_start = st.date_input("Start")
          with col2:
              time_start = st.time_input("Time")
              datetime_start = datetime.combine(date_start, time_start)
  
          col1, col2 = st.columns(2)
          with col1:
              date_end = st.date_input("End")
          with col2:
              time_end = st.time_input("Time End")
              datetime_end = datetime.combine(date_end, time_end)
          submitted = st.form_submit_button("Submit")

i didn’t add the clear_on_submit, but also if i add it - streamlit still updates the time_start & time_end to the default current time, and not to the one i inputted

later on i use datetime_start & datetime_end to filter my views


sometimes it even works, but most of the time the filters revert back to the default state

I think with the way the nested columns and form are, Streamlit is treating it like a new widget instance which is probably more of a bug. Adding keys to make it explicitly the same widget on page load fixes it for me:

with st.sidebar:
    with st.form("my_form"):
          time_filter = datetime.now() - timedelta(days=2)          
          
          st.write('View Period')
          col1, col2 = st.columns(2)
          with col1:
              date_start = st.date_input("Start", key='date_start')
          with col2:
              time_start = st.time_input("Time", key='time_start')
              datetime_start = datetime.combine(date_start, time_start)
  
          col1, col2 = st.columns(2)
          with col1:
              date_end = st.date_input("End", key='date_end')
          with col2:
              time_end = st.time_input("Time End", key='time_end')
              datetime_end = datetime.combine(date_end, time_end)
          submitted = st.form_submit_button("Submit")
2 Likes

works - thank youu soooo much!!!