TypeError when calling a column from data table into a dropdown

I’m trying to build a dropdown filter. I have four dropdowns.

Behind each dropdown is a table columns that contains the options. Each table has one column so far, set to text. I got this code from the forum to connect the columns with the drop down:

def regionDrop_show(self, **event_args):
    """This method is called when the DropDown is shown on the screen"""
    self.regionDrop.items = [row['region'] for row in app_tables.region.search()]
    self.regionDrop.selected_value
    
  def subjectDrop_show(self, **event_args):
    """This method is called when the DropDown is shown on the screen"""
    self.subjectDrop.items = [row['name'] for row in app_tables.subject.search()]
    self.subjectDrop.selected_value      
      
  def schoolDrop_show(self, **event_args):
    """This method is called when the DropDown is shown on the screen"""
    self.schoolDrop.items = [row['type'] for row in app_tables.schooltype.search()]
    self.schoolDrop.selected_value
    
  def ageDrop_show(self, **event_args):
    """This method is called when the DropDown is shown on the screen"""
    self.ageDrop.items = [row['agelevel'] for row in app_tables.age.search()]
    self.ageDrop.selected_value

It throws a TypeError saying: items must be a list of strings or tuples. But not when I run the paragraphs individually, especially without the ageDrop, everything seems to work just fine.

I am a beginner at all this, but willing to learn! So if you have any hint, I will educate myself.

Welcome, @teachpotatoes, to the Anvil Community Forum.

Just two quick guesses.

  1. What is the type of this table column? Number? Or Text? If it’s Number, then you’re going to get a list of numbers, not a list of strings. You can convert to string: str(row['agelevel']).
  2. Can any of these values be None? None is the initial value of every column in every table.
2 Likes

Thank you p.colbert, so kind! Apparently the error was, that the columns contained a bunch of empty rows … I deleted those and now it works with that code! Awesome. Thank you so much!!

1 Like