Form Button logic state cannot be captured

  1. I have a question bank dataframe (qdf) that contains lists of questions and appropriate widgets names for collecting responses. There can be more than 1 widget per question
  2. On my main app page, I show the list of st.buttons on the sidebar based on question count in the question bank (qdf)
  3. If a user presses the sidebar button, then the ShowSingleQuestion function (see below) is called (passed param = Qno & Qname) eg. 1 & Q #1
  4. In ShowSingleQuestion, all widgets names matching the question are pulled into a temp dataframe (tdbf)
  5. Since I do not know the widget count per question as design time, I create a list (tdbfresplst) and append widgets for that question programmatically
  6. Once the form button press, nothing happens, I can’t - for example - set Myvar = “new val” after form button press (sbtn)
  7. If I move the statement Myvar = “new val” before the sbtn logic check, it is processed. It means that sbtn value is not being stored and therefore cannot be conditionally processed
  8. If I use a callback in the example code i.e. sbtn = st.form_submit_button(“Save Response”, on_click=SubmitForm(vqno, tdbfresplst)), I dont know how to pass all the changed widget values in the form
  9. I have shortened the example code for brevity, as I am using this in a multipage app

Why cant I check the sbtn logic state on form submission? is it because of page refresh?

qdf dataframe structure is as follows:
QGrp | Question | RespWidget | LabelText | OptionList | Help
Qgrp1 | Q #1 | RadioButton | Travel Mode | Bike, Car, Bus | RHelp

called function (from main page) is as follows:
def ShowSingleQuestion(vqno, vqnme): # pass Question number and Question code name
tdbf = st.session_state.qdf[st.session_state.qdf[‘Question’] == vqnme] # get all rows (containing widgets) that match question number
tdbfresplst =
with st.form(key = “SgFrm”, clear_on_submit = True):
for j in range(len(tdbf)):
if tdbf.iat[j, 2] == “RadioButton”:
tdbfresplst.append(“Mode of Transport”, options=[“Bike”, “Car”, “Bus”], index=0))

     # other widgets are similarly added in the code...
         sbtn = st.form_submit_button("Save Response")
         if sbtn:   # this is the statement that doesnt seem to work
            Myvar = "new val"   # for further processing...