Autocomplete data source a table vs a list

Hi Shaun,

Thank you for sharing this app. I am wondering how to change the source of the data from the table to a regular list

import tables
from tables import app_tables
import anvil.server

@anvil.server.callable()
def get_search_keys():
“”“Get the keys to populate the Search Hints.”“”
return app_tables.toolbox.search()

So I want to change the source to a list like [“cat”, “dog”, “mouse”] instead of getting the data from a table.

Thank you for your help.

Hi @adhamfaisal

When you click the clone link, you get two apps:

  1. The Search Hints app itself
  2. The example app that uses it (‘Search Hints Example’)

Search Hints Example is where the results list is set up. The get_search_keys method of the SearchHintsDemo form is what returns the results list.

Currently it is:

  def get_search_keys(self, **event_args):
    """Get the search keys from the Data Table."""
    return anvil.server.call('get_search_keys')

You need to change it to:

  def get_search_keys(self, **event_args):
    """Get the search keys from the Data Table."""
    hints = ["cat", "dog", "mouse"]
    return [{'entry': h} for h in hints]

The anvil.server.call('get_search_keys') returns something that behaves like a list of dictionaries, i.e.:

[
  {"entry": "cat"},
  {"entry": "dog"},
  {"entry": "mouse"},
]

So if you want to replace it with your own entries, you need to construct an object that looks like that.

1 Like

It worked! Thank you.

1 Like