Form submit button does get latest values on click

I have a form and I want to submit its values on submit button click.
However when I click on it, it will not pick up latest changes but previous values.

If I do something like:

if submitted:
    on_submit_click(**payload)

it will get the latest values, however that re-renders the same annotation task which I don’t want.
Ideally I want to render a next task after clicking submit.

def on_submit_click(**kwargs):
    resp = send_update(**kwargs)
    st.success('Task submitted')


def render_annotation_task(task_data: Dict):
    """ create a submit form with pre-filled values """
    annotation_config = LABEL_CONF['annotation']
    with st.form('annotation_task', clear_on_submit=True):
        st.video(str(PROJECT_DIR / task_data['local_path']))
        title = st.text_input('title', value=task_data.get('title', ""))
        description = st.text_area('description', value=task_data.get('description', ""))
        language = st.selectbox('language', options=annotation_config['language'],
                                index=_get_lang_index(annotation_config['language'],
                                                      task_data.get('language', "ru")))
        emoji = st.text_input('emoji', value=task_data.get('emoji', ""))
        tags = st.multiselect('tags', options=annotation_config['tags'],
                                    default=task_data.get('video_tags' ,[]))
        payload = dict(title=title, description=description, language=language,
                       emoji=emoji, tags=tags,
                       _id=task_data['_id'], verified=True)
        submitted = st.form_submit_button('Submit', on_click=on_submit_click, kwargs=payload)

Oh i’ve got to use session state in the callback section as described here: Add statefulness to apps - Streamlit Docs

2 Likes