DropDown filter with selected_value

What I’m trying to do:
Hi, I’m trying to build a dynamic filter based on a dropdown menu.

What I’ve tried and what’s not working:
I have build a two anvil server callable functions get_TokenA() and get_TokenC().
They trigger the correct rows in the repeating panels.

Right now they work in two separate forms (form: TokenA, form: TokenB)
But, I would like to combine them in one form using a dropdown menu. When TokenA gets selected the get_TokenA() should be called, but when the dropdown menu changes to TokenC, get_TokenC() should be called.

Code Sample:
I have tried the following:

class TokenA(TokenATemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    self.token_dd.items = [(r['name'], r) for r in app_tables.tokens.search()]
    self.repeating_panel_token.items = anvil.server.call('get_TokenA')
    # Any code you write here will run when the form opens.
  
  def token_dd_change(self, **event_args):
    """This method is called when an item is selected"""
    if self.token_dd.selected_value == 'TokenC':
      self.repeating_panel_token.items = anvil.server.call('get_TokenC')

I am new to Anvil and not very experienced with Python in general, so please tell me if I am not heading in the right direction.

Thank you!

Clone link:
https://anvil.works/build#clone:SZZRTFEZRSHSV2LI=NUWDSO66AC6QF3TS4Y4KJTKA

You are filling your drop down with tuple pairs, where the first item is what’s visible to the user, while the second item is what the selected value gets.

So this isn’t going to work, because you’re expecting the selected value to be a string. Try something like:

if self.token_dd.selected_value['name'] == 'TokenC'
3 Likes

Hi @jshaffstall thank you, this worked!