Address input
Overview
Allows users to find an address using an address finder or enter one manually.
When to use this component
Use this component to help users either:
- search for an address using the ONS Address Index API
- enter an address manually using a set of fields
There is specific guidance on how to ask users for addresses.
How to use this component with the ONS Address Index API
The address input extends the code base used for the autosuggest component.
There are two main ways to use this component with the ONS Address Index API. Addresses can be either:
Non-editable address finder
Include the parameter isEditable: false
. You will also need to set other parameters as shown in the Nunjucks options in the example.
When a user selects an address it is displayed in the address finder input.
The UPRN (unique ID) for the selected address is added to a hidden input. This is posted with the rest of the form data when it is submitted.
If there is an issue with the API, the component will disable the address finder and show an error message.
When using a non-editable address component, you must also use the footer with the royal coat of arms.
The examples on this page use a mock API, for access to the real API internal ONS users will need to raise a Service Now request (opens in a new tab)
If the address finder is not showing in the example or if you have any questions about the component, contact the Design System team
Editable address finder
Include the parameter isEditable: true
. You will also need to set other parameters as shown in the Nunjucks options in the example.
When a user selects an address, it will be displayed in a set of manual fields. This allows the user to check and edit the address.
If the address is changed, the UPRN (unique ID) is removed and not posted with the rest of the form data.
If there is an issue with the API, the manual fields will be shown instead of the address finder.
When using an editable address component, you must also use the footer with the royal coat of arms.
Using the API
The ONS Address Index API uses a JSON Web Token (JWT) to allow for the transfer of data. Email the Design System working group at ons.design.system@ons.gov.uk (opens in a new tab) to let them know your requirements and to set up trusted domains for the API.
Set the values for the parameters APIDomain
and APIDomainBearerToken
to allow queries to be passed to the API. Also include the parameter "externalInitialiser": true
to bypass the default autosuggest methods.
A query is sent to the relevant API endpoint after three characters have been entered into the address finder input. The API will return addresses in groups when the user searches by postcode. If the user searches by another part of the address, the API will return the best matches for that search term.
Validation
The address autosuggest provides client-side validation when the parameter mandatory: true
is used. The validation checks if the user has:
- entered something in the address finder input
- selected an address from the results
- selected an address from the results and then edited it in the address finder input (non-editable variant only)
You will need to include parameters for these error messages:
If the address finder input is empty
Use “Enter an address” for the parameter: errorMessageEnter
If no address is selected from the results
Use “Select an address” for the parameter: errorMessageSelect
If a selected address has been edited in the address finder input
Use “Select an address” for the parameter: errorMessageSelect
Other API messages
Use the following error messages to improve the address finder results and deal with any loading issues:
If no results are found
Use “No results found. Try entering a different part of the address” for the parameter: noResults
.
If the postcode returns too many results
Use “[number of addresses] results found. Enter more of the address to improve results” for the parameter: tooManyResults
.
If more of the address or postcode are needed to get results
Use “Enter more of the address to get results” for the parameter: typeMore
.
If there is an error with the API during use of the editable address finder
Use “Sorry, there is a problem loading addresses. Enter address manually” for the parameters: errorMessageAPI
and errorMessageAPILinkText
.
If the API is down before use of the editable address finder
There is a status check when the page loads and initialises the component. If the API is down, a set of fields will allow the user to enter an address manually. This also happens if JavaScript is turned off.
If the API is down before or during use of the non-editable address finder
The input will be disabled and an error message shown.
Use “Sorry, there is a problem. We are working to fix it. Please try again later or contact us for more help.” for the parameters: errorMessageAPI
and errorMessageAPILinkText
.
How to use this component for manual address entry
Include the parameter manualEntry: true
. You will also need to set other parameters as shown in the Nunjucks options in the following example.
Help improve this page
Let us know how we could improve this page, or share your user research findings. Discuss the ‘address input’ component on GitHub (opens in a new tab)