Skip to main content

Configuration Reference

A complete reference for every option accepted by PostcodeLookup.setup. Only context, apiKey and outputFields are required; everything else is optional and has a sensible default.

Callbacks have their own page - see Callbacks. Message strings and CSS classes are summarised here and covered in depth under Messages and CSS Classes.

Required

context

string | HTMLElement · required

The area on your page where Postcode Lookup renders its interface - typically a <div>, referenced by CSS selector or a direct element reference.

apiKey

string · required

API Key from your Ideal Postcodes account. Typically begins ak_.

outputFields

object · default {}

Specifies where to send address data when an address is selected. Maps an address attribute to an input field, identified by a CSS selector string or an HTMLElement.

{
line_1: "#line_1",
line_2: "#line_2",
line_3: "#line_3",
post_town: document.getElementById("post_town"),
postcode: document.getElementById("postcode")
}

The attribute names match the Address response object - e.g. street name populates from thoroughfare. The full list is in the UK address data guide. Fields assigned with a query selector are evaluated lazily.

Search behaviour

strictlyPostcodes

boolean · default true

When true, only postcodes are searched. Set to false to search the term as a complete address, enabling queries such as SW1A 2AA 10.

limit

number · default 10

Maximum number of addresses presented after an address search. Only applies when strictlyPostcodes is false.

cooloff

number · default 500

Milliseconds the search button stays disabled after a click, preventing double presses. Set to 0 to disable.

selectSinglePremise

boolean · default false

When true, a single-premise result is populated immediately without showing the selection dropdown. onAddressSelected still fires.

autoSearchSingleSuggestion

boolean · default true

When a postcode lookup fails but returns exactly one suggestion, the input is updated with that suggestion and a new search is triggered automatically.

Address output and formatting

titleizePostTown

boolean · default true

Title-case the post town (true) or keep it in all caps (false). All caps is recommended by Royal Mail's good addressing guidelines.

removeOrganisation

boolean · default false

Strips the organisation name from the address lines. Note that some "Large User" addresses consist only of an organisation name, post town and postcode.

populateCounty

boolean · default true

Set to false to suppress county from being populated.

Input field

OptionTypeDefault
inputstring | HTMLInputElement | nullnull - supply your own input instead of the generated one
inputIdstring | nullnull
inputClassstring | null"idpc-input"
inputAriaLabelstring"Search a postcode to retrieve your address"
placeholderstring"Search your postcode"
inputStyleobject{} - inline styles for the input
autocompletestring"none" - sets the input's autocomplete= attribute to prevent clashing browser autofill

Button

OptionTypeDefault
buttonstring | HTMLButtonElement | nullnull - supply your own button
buttonIdstring | nullnull
buttonLabelstring"Find my Address"
buttonAriaLabelstring"Search for address using postcode"
buttonClassstring | null"idpc-button"
buttonStyleobject{} - inline styles for the button

Address dropdown

OptionTypeDefault
selectContainerstring | HTMLDivElement | nullnull - element the results <select> is inserted into
selectContainerIdstring | nullnull
selectContainerClassstring | null"idpc-select-container"
selectIdstring | nullnull
selectClassstring | null"idpc-select"
selectAriaLabelstring | null"Select your address"
selectStyleobject{} - inline styles for the <select>

postcodeSearchFormatter

function

Converts an address object into the suggestion string shown in the dropdown after a postcode search.

addressSearchFormatter

function

Converts an address object into the suggestion string shown after a freeform address search.

Messages

Override any user-facing string. See Messages.

OptionDefault
msgSelect"Please select your address"
msgDisabled"Finding addresses..."
msgNotFound"Your postcode could not be found. Please type in your address"
msgAddressNotFound"We could not find a match for your address. Please type in your address"
msgError"Sorry, we weren't able to get the address you were looking for. Please type in your address"
msgUnhide"Enter address manually"

Message container

OptionTypeDefault
messagestring | HTMLParagraphElement | nullnull - supply your own message container
messageIdstring | nullnull
messageClassstring | null"idpc-error"
messageStyleobject{} - inline styles for the message container

Hiding address fields

hide

(string | HTMLElement)[] · default []

Elements to hide with display: none; when Postcode Lookup initialises. They are unhidden when an address is selected or the user opts for manual entry.

{
hide: [
"#line_1",
document.getElementById("line_2"),
document.querySelector("#line_3"),
],
}

Enabling this also renders a clickable element offering manual entry. Provide your own with unhide, or customise the default with msgUnhide and unhideClass.

unhide

string | HTMLElement | null · default null

A custom clickable element to unhide fields hidden with hide.

unhideClass

string · default "idpc-unhide"

CSS class applied to the default unhide element.

Container styling

contextStyle

object · default {}

Inline styles applied to the context container.

Key checking

checkKey

boolean · default true

Checks the key is usable before initialising. The check can fail if:

  • Your key has no remaining lookups
  • Your key has run into its daily lookup limit
  • Your key is requested from a URL not on your allowed list
  • The user has exceeded their daily limit

On failure the widget does not initialise. Use the onFailedCheck callback to handle this case.

DOM scoping

OptionTypeDefault
scopeDocument | HTMLElement | stringwindow.document - scopes the operable area of the DOM
documentDocumentwindow.document
outputScopestring | HTMLElement | Document | nullnull - narrows where output fields are searched for

Network and client

Inherited from the underlying API client. Defaults suit the production API and rarely need changing.

OptionTypeDefault
baseUrlstring"api.ideal-postcodes.co.uk"
versionstring"v1"
tlsbooleantrue
timeoutnumber10000 (ms)
strictAuthorisationbooleanfalse
headerobject{}
tagsstring[][]

Callbacks

Every lifecycle hook is documented on the Callbacks page: onLoaded, onFailedCheck, onButtonTrigger, onLookupTriggered, shouldLookupTrigger, onSearchCompleted, onSearchError, onAddressesRetrieved, onAddressSelected, onAddressPopulated, onSelectCreated, onSelectRemoved, onUnhide and onRemove.