mkhorasani / Streamlit-Authenticator

A secure authentication module to validate user credentials in a Streamlit application.
Apache License 2.0
1.37k stars 229 forks source link

Clear forms on submit #130

Closed Volker-H closed 3 months ago

Volker-H commented 4 months ago

Hi, first of all - the library is really great. Many thanks for making authentication that much easier!

One thing that I couldnt figure out yet is how to clear the forms after the User submits. e.g. the update_user_detail or the reset_password --> the Information entered by the User remains after submitting.

Is there a parameter to add?

Best Volker

mkhorasani commented 4 months ago

Hi @Volker-H thank you for reaching out. You can try using st.experimental_rerun() to clear to fields. Let me know if it helps.

Volker-H commented 4 months ago

Thank you for your quick reply! Hmm is this the right place? Also tried it in the update function - but it´s not working.

if st.session_state["authentication_status"]:
    try:                
        if authenticator.update_user_details(st.session_state["username"]):
            st.success('Änderungen aktualisiert')
            update_ufile()
            st.experimental_rerun()
    except Exception as e:
        st.error(e) 

I also tried st.rerun() - no success.

I'm surprised that not more people have this problem.

mkhorasani commented 4 months ago

I will need to see if I can implement this somehow in the logic of the package itself. Stay tuned!

Volker-H commented 4 months ago

one addition, if I build forms myself I simply use:

with st.form('get_data', clear_on_submit=True):

After hitting the submit button the form is cleared.

mkhorasani commented 4 months ago

Excellent, will add this to a future release!

fsmosca commented 3 months ago

I have a branch, that supports form key definitions and clear_on_submit parameter. But this is only for forgot password. Will update to other methods if I have time.

        Usage examples
        --------------
        >>> authenticator.forgot_password()
        >>> authenticator.forgot_password('formkey')
        >>> authenticator.forgot_password('formkey', location='sidebar')
        >>> authenticator.forgot_password('myformkey', location='main', fields={'Form name': 'Forgot password with key'})
        >>> authenticator.forgot_password('formkey', clear_on_submit=True, location='main', fields={'Form name': 'Forgot password'})

Added an example in other issue.

mkhorasani commented 3 months ago

Dear all the argument to clear forms has been added to all the widgets in the latest release v0.3.2.