Dropdown component has a bug

My intention is to use two dropdown components to filter on a table. When I select an item from the first one, let’s say region, a second dropdown is shown and lists only cities in the chosen previous selection. Now I should be able to select a city. Unfortunately, if there is only one city, it cannot be selected. This seems to be a bug.

Here is an example code:

CLIENT:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.server

class Form1(Form1Template):
def init(self, **properties):
self.init_components(**properties)
self.dropdown_1.items = anvil.server.call(‘get_dropdown_data’)

def dropdown_1_change(self, **event_args):
print(self.dropdown_1.selected_value)

SERVER:
import anvil.server

@anvil.server.callable
def get_dropdown_data():
#return [“Option 1”, “Option 2”, “Option 3”] # works
return [“Option 1”] # cannot select Option 1 any more…

The bug is in the implementation.

A dropdown with one item doesn’t allow you to select the item, that’s how dropdowns work.

You have two options here:

  1. Add one more "<Please select an option>" item to the dropdown and select that one, so you force the user to select
  2. When you assign the list of items to the dropdown, also explicitly select the first item and run the code for that selection
1 Like

Dear Stefano,

Thanks for your prompt answer.

So that is the way the dropdown component is implemented. I did not expect it to work like that.

In any case, thank you also for your hints. It looks like these will resolve my issue.

A post was split to a new topic: Plotly add_trace