Autocomplete Input
Type-ahead search with remote data fetching and dropdown results
Built-in Features
What you get out of the box with zero configuration
Initializes automatically on any input with autocomplete="on" inside a container with data-url. For dynamic content, call NDS.Autocomplete.reinit().
Matching characters in results are highlighted with <mark> tags. Results display in a dropdown built on the NDS Dropmenu component.
Arrow keys navigate results, Enter selects the active item, Escape closes the dropdown. The active item scrolls into view automatically.
API requests are debounced at 300ms. Previous in-flight requests are cancelled via AbortController. Loading state shows on the input during fetch.
Works with Arabic and English content. Empty state message adapts to the page language. RTL and LTR layouts supported.
Selected values sync to the input. Clear button resets the selection. Works with the forms validation and status API.
Usage Guidelines
When and how to use autocomplete inputs effectively
When to Use
- Search fields that query a remote API for suggestions as the user types
- Large datasets where showing all options in a select dropdown is impractical
- Service search, city lookup, product search, or any entity search
- Set
data-min-charsto control when fetching begins (default: 3 characters) - For static option lists, use a select dropdown instead
JavaScript API
Configuration Attributes
data-urlon the container: API endpoint that returns JSONdata-name: JSON field name to display in results (default: "Title")data-min-chars: minimum characters before fetching starts (default: 3)data-query-param: query string parameter name sent to the API (default: "q")data-results-path: dot notation path to the results array in the response (e.g. "response.items"). Without it, the component auto-detects flat arrays or objects withresultsordatakeys
API Response Format
The component sends a GET request with the query as a URL parameter (e.g. /api/services?q=term). The API handles filtering and returns JSON in one of these formats: