top of page
Country Autocomplete

Country Autocomplete

Automatically complete country names while typing. Use your keyboard to select the country you want.

Intermediate.png

Intermediate

3K

Published:

June 22, 2021

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example, we created a collection named Countries, which stores a list of country names. When the site visitor starts typing in the country field, suggestions for country names that have the same prefix as the characters the visitor typed are displayed using a repeater. The site visitor can either continue typing or choose his country using the keyboard or the mouse.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It


Page Elements


We added the following elements:


  • 3 text input elements: name, email and country.

  • Repeater: for displaying the country name suggestions.

  • Submit button: for submitting the form.



Page Code


First we declare some constant values, such as the colors of the repeater’s items and the maximum number of items to be displayed.


We also manage 3 global variables:


  • listSize: the amount of currently displayed items in the list.

  • currIndex: the index of the current selected item in the repeater.

  • debounceTimer: helps to provide smoother behavior for the search functionality.


When the site visitor starts typing in the country input element, we send a query to the Countries collection. This query finds the country names that start with the current input value. Those countries are displayed in the repeater, with each country in its own repeater item. Using the keyboard arrow keys, the user can navigate up and down the repeater items and select a country by pressing the Enter key. The country menu can be closed by pressing the Esc key. Visitors can also use the mouse. When one navigates to an item using the keyboard arrows, that item’s color changes to indicate it will be selected if the Enter key is pressed.



When the visitor clicks the Send button, the form is submitted to another database collection.

APIs We Used

Non-code example.

Non-code example.

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

City Weather

City Weather

Get weather information according to city

Intermediate.png

Intermediate

Maintain Page State

Maintain Page State

Maintain the state of your repeater while navigating to a dynamic page.

Intermediate.png

Intermediate

Create a Quiz

Create a Quiz

Create a quiz that randomly selects questions from a database collection.

Intermediate.png

Intermediate

Anchor 2
bottom of page