[Flask] Is there a way to periodically save form data without requiring the user to click on a button?

Marc Branchaud marcnarc at xiplink.com
Thu Apr 23 11:05:45 EDT 2020


On 2020-04-23 3:17 a.m., CCP Dragonedge wrote:
> Hi,
> 
> Let's say I have 10 input fields on a form. The user has input data into 
> four or five of them. Before he completes, he is called away from his or 
> her desk - for a long time (eg meetings, phone call, etc).
> 
> Let's assume that the user can't click on the Submit button yet because 
> all of the fields haven't been input. So, the record isn't saved...
> 
> Is there a way for Flask to save it on the client side? I read about 
> Flask-Socketio, but that seems kind of overkill.
> 
> Or is this outside the scope of Flask, and in the realm of Javascript? I 
> found out about HTML5 Local Storage (or WebStorage). To my 
> understanding, however, that's in Javascript, so then AJAX gets involved 
> if I want to pass the saved value back to Flask, right?

Right -- AJAX, or some other form of communication.  Flask can support 
whatever you want to use.

In our UI we automatically save input data to the server, separately 
from the user "submitting" the data.  (We basically have lots of forms 
presented on different pages, and the user wants to fill in everything 
before "applying" the updates all at once.)  We use AJAX to save the 
user's work as they go.  So even if they close the browser and come back 
days later, their work is still where they left it.

One thing about this model is that you're faced with a choice: Do you 
save the changes on every keystroke?  In our system that's impractical, 
so we only save when the input blurs.  (We could also implement a 
timeout to save after the user stops typing, but we haven't.)

There can be tricky edge cases to this approach, depending on your app's 
complexity.

		M.



More information about the Flask mailing list