Dynamic Datalist: Autocomplete from an API :: Aaron Gustafson
aaron-gustafson.com·1d
🔌API Development
Preview
Report Post

HTML’s datalist element provides native autocomplete functionality, but it’s entirely static—you have to know all the options up front. The dynamic-datalist web component solves this by fetching suggestions from an API endpoint as users type, giving you the benefits of native autocomplete with the flexibility of dynamic data.

This component is a modern replacement for my old jQuery predictive typing plugin. I’ve reimagined it as a standards-based web component.

Basic usage

To use the component, wrap it around your input field and specify an endpoint:

<dynamic-datalist endpoint="/api/search">
<label for="search">Search
<input type="text" id="search" name="search"
placeholder="Type to search..."
>
</lab...

Similar Posts

Loading similar posts...