What I’m trying to do:
My goal is to have a list of non-identical questions & answers available for users to select what their interests are using radio buttons & checkboxes and based on provided answers anvil should hide feedback/questions not related to user input.
What I’ve tried and what’s not working:
I’m assuming to reach my goal I need a ton of if, elif, and else statements to connect multiple questions.
- I am unsure if I’m grouping things accordingly. Maybe there’s a better table format instead?
- I keep getting maximum call stack size exceedance errors. Assuming Anvil doesn’t like referencing the same design components multiple times. Have tried to see if clearing links helps. But didn’t work.
Code Sample:
# this is a formatted code snippet.
# paste your code between ``` from ._anvil_designer import EnvironmentalToolkitTemplate
from anvil import *
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.server
class EnvironmentalToolkit(EnvironmentalToolkitTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
def form_environmental_show(self, **event_args): #links to startup form homepage
"""This method is called when the form is shown on the page"""
self.layout.reset_links()
self.layout.Environmental_Toolkit.role = 'selected'
def COC_Class_show(self, **event_args): #Q1 label event show
"""This method is called when the Label is shown on the screen"""
def PFAS_RB_clicked(self, **event_args): #Q1 radio button event
"""This method is called when this radio button is selected"""
def PAH_RB_clicked(self, **event_args): #Q1 radio button event
"""This method is called when this radio button is selected"""
def PCB_RB_clicked(self, **event_args): #Q1 radio button event
"""This method is called when this radio button is selected"""
def TM_RB_clicked(self, **event_args): #Q1 radio button event
"""This method is called when this radio button is selected"""
def PFASofInterest_show(self, **event_args): #Q2 radio button event show
"""This method is called when the Label is shown on the screen"""
def PFASofInterest_hide(self, **event_args): #Q2 radio button event hide
"""This method is called when the Label is removed from the screen"""
def PFOA_CB_change(self, **event_args): #Q2 checkbox event
"""This method is called when this checkbox is checked or unchecked"""
def LPFOS_CB_change(self, **event_args): #Q2 checkbox event
"""This method is called when this checkbox is checked or unchecked"""
def EightTwoFTS_CB_change(self, **event_args): #Q2 checkbox event
"""This method is called when this checkbox is checked or unchecked"""
#Create Question 1 Group
self.COC_Class.group_name = "Q1Group"
#Contaminant of Concern Class radio button selections
rb1 = self.PFAS_RB_clicked (group_name="Q1Group", value="A")
rb2 = self.PAH_RB_clicked (group_name="Q1Group", value="B")
rb3 = self.PCB_RB_clicked (group_name="Q1Group", value="C")
rb4 = self.TM_RB_clicked (group_name="Q1Group", value="D")
#Create Question 2 Group
lb2show = self.PFASofInterest_show (group_name="Q2Group")
lb2hide = self.PFASofInterest_hide (group_name="Q2Group")
cb1 = self.PFOA_CB_change (group_name="Q2Group")
cb2 = self.LPFOS_CB_change (group_name="Q2Group")
cb3 = self.EightTwoFTS_CB_change (group_name="Q2Group")
if rb1.selected is True:
print("Q2Group")
elif rb1.selected is False:
self.remove_component(lb2hide)
self.remove_component(cb1)
self.remove_component(cb2)
self.remove_component(cb3)
if rb2.selected is True:
print("Q3Group")
if rb3.selected is True:
print("Q4Group")
if rb4.selected is True:
print("Q5Group")
Clone link:
share a copy of your app