Live Search
Get search results as you type.
Live search watches a search field and makes AJAX requests as you type.
Examples
The base live-search class defines the search form. The live-search-search-text class identifies the
text field to watch; the field the consumer types search terms into.
Please note, Github pages doesn't allow AJAX (or fetch), so the examples on this page don't work properly on the public documentation website. They work fine when running the local development server.
Basic Search Example
Important Attributes
The following attributes are required for Live Search to function. They are all placed on the root form element,
the same form element the live-search is placed on.
| Attribute | Description |
|---|---|
data-live-search |
The presence of the attribute data-live-search enables Live Search on the form. No value is required. |
data-target |
The attribute data-target identifies the HTML element to place the search results inside. |
data-hide |
The attribute data-hide identifies the HTML elements to hide while the search results are being displayed, and reveal when the search is cancelled. |
action |
The action attribute identifies the URL to use for the AJAX search request. The results are expected to be in HTML format. |
Two Hide Targets Example
Search Form in a Toolbar Example
Inline search forms can be placed inside a toolbar.
Notice the toolbar-group class is placed inside the form on the same element containing the input-group, trying to
place the toolbar-group class on other elements will likely produce undesirable results.
Complex Search Form Example
Search forms can have any number of fields and the AJAX request will submit them along with the
live-search-search-text field.