A form with 6-8 fields and a "Submit" button to update a database.
An additional button to trigger a job in a Kubernetes cluster using the form's field values.
Problem:
When users change values in the form but don’t press the “Submit” button and then try to trigger the job, they should be notified about unsaved changes. However, I’m struggling to detect these changes consistently.
What I’ve Tried:
Capturing user inputs outside the form
Didn’t work well with the Streamlit form structure.
Using st.session_state to track changes
* This partially works, but the issue is:
* When the user changes a value in the form for the first time, the change isn’t captured immediately.
* On the first click of the job-trigger button, it doesn’t detect changes.
* On subsequent clicks, it correctly detects changes.
What I Need:
A reliable way to track unsaved changes in the form and alert the user before triggering the job.
Any advice or examples on how to handle this scenario effectively in Streamlit would be greatly appreciated!
I don’t think you can do that with forms. The applications cannot see the changes in the form until the submit button is pressed. That is pretty much the definition of a form and it is at odds with your intent.
Just don’t use a form. I don’t think I understand enough of your use case or the challenges you are facing to be much more specific. I suppose you can still have a button that saves the data and another button that triggers the job, and you can detect unsaved changes by comparing the widget values to the saved data.
I don’t know if it helps in your instance, but forms can also have more than one submit button. So you could have one button to only save the values, and another to both save the values and trigger a job. Thus instead of warning about unsaved changes, your job trigger button could just be another form submit button.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.