AutoComplete

AutoComplete

Learn how to use AutoComplete input type for searching and selecting from large datasets with real-time filtering. AutoComplete provides a better user experience than dropdowns when dealing with large lists of options.

A comprehensive guide for using AutoComplete in form configurations. This guide covers how to configure AutoComplete inputs with remote data, local options, filtering, and custom configurations.


Overview

The FormInputType.autocomplete allows you to:

  1. Search large datasets - Efficiently search through hundreds or thousands of options

  2. Real-time filtering - Filter options as the user types

  3. Remote data loading - Load options from API endpoints dynamically

  4. Better UX for large lists - Provide a better experience than dropdowns for large option sets

  5. Customizable search behavior - Configure minimum characters, delay, and search parameters


Use Case 1: AutoComplete with Remote Data

Scenario

You have a large list of users and want users to search and select a user efficiently. Instead of loading all users upfront, you want to search them dynamically from the API.

Configuration

Example from Codebase

File: src/app/dashboard/project/services/project.service.ts (lines 82-101)

Parameters Explained

Parameter
Type
Description
Required

inputType

FormInputType.autocomplete

Specifies AutoComplete input type

βœ… Yes

autoCompleteConfiguration

AutoCompleteConfiguration

Configuration object for AutoComplete. Note: Property name is autoCompleteConfiguration (camelCase), but TypeScript interface is AutoCompleteConfiguration (PascalCase)

βœ… Yes

autoCompleteConfiguration.optionLabel

string

Property name to display in options

βœ… Yes

autoCompleteConfiguration.valueBy

string

Property name to use as value

βœ… Yes

autoCompleteConfiguration.filterBy

string

Property name to filter by

Optional

autoCompleteConfiguration.showClear

boolean

Show clear button

Optional

autoCompleteConfiguration.filter

boolean

Enable filtering

Optional

autoCompleteConfiguration.options

any[]

Array of local options (use with async manualInputsFn)

Optional

autoCompleteConfiguration.remoteDataConfiguration

object

Configuration for remote data loading

Optional

autoCompleteConfiguration.minLength

number

Minimum characters before search

Optional

autoCompleteConfiguration.delay

number

Delay in milliseconds before search

Optional

autoCompleteConfiguration.placeholder

string

Placeholder text

Optional

⚠️ Important Note on Property Name:

  • In your code, use autoCompleteConfiguration (camelCase with capital C)

  • The TypeScript interface type is AutoCompleteConfiguration (PascalCase)

  • This follows TypeScript/JavaScript naming conventions where property names are camelCase and type names are PascalCase

How it Works

  1. User Types: User starts typing in the AutoComplete field

  2. Minimum Length Check: After minLength characters (e.g., 2), search is triggered

  3. Delay: Waits for delay milliseconds (e.g., 300ms) to avoid excessive API calls

  4. API Call: Makes request to endPoint with search query

  5. Response Mapping: Maps API response using mapHttpResponse function

  6. Display Options: Shows filtered options matching the search query

  7. Selection: User selects an option, value is set using valueBy property


Use Case 2: AutoComplete with Local Options

Scenario

You have a smaller, predefined list of options that you want to load upfront and filter locally.

Configuration

How it Works

  1. Load Options: Options are loaded upfront (synchronously or asynchronously)

  2. Local Filtering: As user types, options are filtered locally

  3. No API Calls: No additional API calls needed during typing

  4. Faster Response: Instant filtering without network delay


Use Case 3: AutoComplete with Custom Search Logic

Scenario

You need custom search logic that searches multiple fields or applies complex filtering.

Configuration


Complete Examples

Example 1: AutoComplete with Local Options Loaded from API (Real Implementation)

This example shows a real implementation from the codebase where users are loaded from API and used in AutoComplete with local filtering.

File: src/app/dashboard/project/services/project.service.ts (lines 82-101)

Result:

  • Users are loaded from API when form opens

  • User types "John" β†’ Local filter searches through loaded users

  • Shows filtered results: "John Doe", "John Smith", etc.

  • User selects a user β†’ user_id is set to selected user's ID

Key Points:

  • Uses async manualInputsFn to load users before form renders

  • Uses autoCompleteConfiguration (note the capital C) property name

  • Options are loaded once and filtered locally (no API calls while typing)

  • Better for smaller datasets (< 100 items) where loading all options is acceptable


Example 2: AutoComplete with Local Options


Example 3: AutoComplete with Multiple Fields Display


Comparison Table

Feature
AutoComplete
Dropdown

Best for

Large datasets (100+ items)

Small datasets (< 50 items)

Search

βœ… Real-time search

⚠️ Filter only (if enabled)

Performance

βœ… Efficient for large lists

❌ Slow with large lists

User Experience

βœ… Type to search

⚠️ Scroll to find

Remote Data

βœ… Optimized for remote

βœ… Supports remote

Loading

βœ… Lazy loading

⚠️ Loads all options


Best Practices

  1. Use AutoComplete for large lists: When you have more than 50-100 options, AutoComplete provides better UX

  2. Set appropriate minLength: Require at least 2-3 characters before searching to reduce API calls

  3. Add delay for remote searches: Prevent excessive API calls with a delay

  4. Use remoteDataConfiguration for large datasets: Don't load all options upfront

  5. Provide helpful placeholders: Guide users on what to search for

  6. Map API responses properly: Ensure response format matches expected structure

  7. Enable showClear for optional fields: Allow users to easily clear selection


Common Patterns

Pattern 1: Simple Remote AutoComplete

Pattern 2: AutoComplete with Custom Query Params

Pattern 3: AutoComplete with Local Options


  • Dropdown Configuration - Learn about dropdown inputs

  • Async Manual Inputs - Understand async data loading

  • Form Input Types - See all available input types


Summary

AutoComplete provides an efficient way to search and select from large datasets:

  • Remote data support: Load options dynamically from API

  • Real-time filtering: Filter options as user types

  • Configurable search: Set minimum characters, delay, and search parameters

  • Better UX: Ideal for large lists (100+ items)

  • Flexible configuration: Support both remote and local options

This feature enables efficient searching and selection in forms, especially when dealing with large option sets that would be impractical to display in a dropdown.

Last updated