Background: I want to create a survey form which required a checkbox-tree selection where a checkbox is checked, then it will expand for more check-boxes until 4 levels. I found a contribution (It is what I want it to look like) but it unable to add input text. The post is here. Now, I have to find another way to achieve the same objectives due to deadline.
Problem: With the code without a submit form, it works as intended. The multiselect will then open “Sector” multiselect and if “Others” is selected, it will open the text input for user to key in.
However, it will not work in a form. I try to understand session.state but seems the state will not change, How can I let the create a form but able to the next level selection base on precedent selection?
Without form submit button (able to select base on precedent selection)
st.write(st.session_state)
attributes = st.multiselect('Choose attributes', ['Sector', 'Revenue'])
st.write(st.session_state)
if "Sector" in attributes:
sector = st.multiselect('Choose sectors', ["Service", "Manufacturing","Consulting","Others"])
if "Others" in sector:
st.text_input(label="key in others sector")
if "Revenue" in attributes:
revenue = st.multiselect('Choose revenues', ["over 1 mil", "below 1 mil","no revenue"])
if "no revenue" in revenue:
st.text_input(label="key in the reason")
st.write(st.session_state)
Not able to select base on precedence selection
with st.form('my_form'):
st.write(st.session_state)
attributes = st.multiselect('Choose attributes', ['Sector', 'Revenue'])
st.write(st.session_state)
if 'Sector' in st.session_state:
st.write("sector not in")
st.write(st.session_state)
else:
st.write("sector is in")
if "Sector" in attributes:
sector = st.multiselect('Choose sectors', ["Service", "Manufacturing","Consulting","Others"])
if "Others" in sector:
st.text_input(label="key in others sector")
if "Revenue" in attributes:
revenue = st.multiselect('Choose revenues', ["over 1 mil", "below 1 mil","no revenue"])
if "no revenue" in revenue:
st.text_input(label="key in the reason")
st.form_submit_button('Submit')
st.write(st.session_state)
Please advise how to make it work. I also open if checkbox is able to work in my case. Thanks!