Inputs Autocomplete
Contents
<input type="hidden" name="filters.people" value="" data-autocomplete-hidden />
<div class="govuk-form-group">
<label class="govuk-label govuk-!-font-weight-bold dpr-inline-label" for="filters.people">
People
</label>
<div class="govuk-input__wrapper">
<input class="govuk-input autocomplete-text-input-box govuk-input--width-20" id="filters.people" name="label.filters.people" type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="filterspeople-list" aria-haspopup="listbox" data-minimum-length="" placeholder="Search" pattern=".+" required="">
<div class="govuk-input__suffix" aria-hidden="true">🔍</div>
</div>
</div>
<div class="autocomplete-text-input-list-container">
<ul id="filterspeople-list" class="autocomplete-text-input-list autocomplete-text-input-list--hidden" role="listbox" aria-label="People">
<li id="filterspeople-list-0" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Magnar Azure">
Magnar Azure
</li>
<li id="filterspeople-list-1" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Quinctus Zainabu">
Quinctus Zainabu
</li>
<li id="filterspeople-list-2" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Paraskevi Munroe">
Paraskevi Munroe
</li>
<li id="filterspeople-list-3" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Gundega Johanneke">
Gundega Johanneke
</li>
<li id="filterspeople-list-4" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Konjit Taina">
Konjit Taina
</li>
<li id="filterspeople-list-5" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Lennie Alma">
Lennie Alma
</li>
<li id="filterspeople-list-6" role="option" aria-selected="false" class="autocomplete-option autocomplete-text-input-item-hide" data-value="" data-display="Murad Ali">
Murad Ali
</li>
</ul>
</div>
</div>
Nunjucks macro options
| Name| Type| Required| Description|
| -----------------------| ------| --------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| id| string| Yes| A unique identifier for the input.|
| name| string| Yes| The name of the input.|
| value| string| No| The current value of this input.|
| labelText| string| No| The text of the label displayed above this input.|
| items| array| No| A static list of options to choose from. See Items. This is ignored if the dynamic resource endpoint is set.|
| minimumLength| number| No| The minimum length of text before options are fetched/displayed.|
| dynamicResourceEndpoint| string| No| The API endpoint to call to fetch the dynamic values. This should contain a
{prefix} token to be replaced by the current text value when the request is made.|
Items
| Name | Type | Required | Description |
|---|---|---|---|
| text | String | Yes | The value to be displayed and returned for the option. |
{%- from "dpr/components/_inputs/autocomplete-text-input/view.njk" import dprAutocompleteTextInput -%}
{{
dprAutocompleteTextInput({
id: 'people',
name: 'people',
options: [
{ text: 'Magnar Azure' },
{ text: 'Quinctus Zainabu' },
{ text: 'Paraskevi Munroe' },
{ text: 'Gundega Johanneke' },
{ text: 'Konjit Taina' },
{ text: 'Lennie Alma' },
{ text: 'Murad Ali' }
],
text: 'People',
minimumlength: 1
}, [], 'filters.')
}}```
</div>
</div>
</div>
## Overview
### When to use
Use this component when users need to choose from a large set of options. Either populated statically, or dynamically from a remote API endpoint.
Example uses:
- Choosing an establishment name.
- Searching for a post code.
- Searching for a person's name.
### When not to use
Do not use this component for a small set of options, or where discovery of the available options is important. In these cases a Radio input of similar may be a better option.