Retyping in the text area reloads the page instead of outputting the text after button is clicked

Hi @azzi thankโ€™s for explanation. It is still a little bit unclear for me what you would like to achieve at the end.

Some comments:

  1. As you probably know streamlit reruns application from top to bottom on user interaction
  2. To save state of variables you may use st.session.state. Here you can find documentation and explanation in a tutorial from @asehmi

Please note that in your code you are creating three separate text forms which values are stored separately.


import streamlit as st

def callback():
    st.write("callback triggered")

cont1 = st.empty()
with cont1.container():
    st.write("This is a first text field")
    prompt = st.text_area(
        "Text", placeholder="prompt", key="promptKey", label_visibility="hidden"
    )
    st.session_state
    submit_button = st.button("Submit โ–ถ")

cont2 = st.empty()
with cont2.container():
    sample_question = '<p style="font-family:sans-serif; color:Black; font-size: 18px; position: relative; top: 20px">Examples</p>'
    st.markdown(sample_question, unsafe_allow_html=True)

    st.markdown(
        """<hr style="height:5px;border:none;color:#333;background-color:#333;" /> """,
        unsafe_allow_html=True,
    )

    col1, col2 = st.columns(2)
    with col1:
        buttonName1 = "Hello!"
        button1 = st.button(buttonName1)

    with col2:
        buttonName2 = "How are you?"
        button2 = st.button(buttonName2)


def helpButtons(buttonName):
    cont1.empty()
    cont2.empty()
    st.write("This is a third text field")
    buttonPrompt = st.text_area("", value=buttonName, key="third_form")
    st.session_state
    submit_button3 = st.button("Submit", key="s3")
    if submit_button3:
        cont1.empty()
        cont2.empty()
        submitPrompt = st.text_area(
            "",
            value=buttonPrompt,
            key="second_form",
            on_change=callback,
        )
        submit_button4 = st.button("Submit", key="s4")


if prompt:
    cont1.empty()
    cont2.empty()
    st.write("This is a second text field")
    prompt = st.text_area("", value=prompt, key="second_form")
    st.session_state
    submit_button2 = st.button("Submit")
else:
    if button1 | button2:
        if button1:
            helpButtons(buttonName=buttonName1)
        elif button2:
            helpButtons(buttonName=buttonName2)