Docs · Libraries
JavaScript autocomplete
One script tag adds as-you-type address completion to any form — New Zealand (LINZ). No dependencies, no build step. Suggestions are free; resolving the address the user picks costs one credit.
Quick start
Mark up your form, then initialise the widget with a domain token (a browser-restricted API key).
HTML
<label for="address_line_1">Address line 1</label>
<input id="address_line_1" type="text">
<label for="address_line_2">Address line 2</label>
<input id="address_line_2" type="text">
<label for="suburb">Suburb</label>
<input id="suburb" type="text">
<label for="state">State</label>
<input id="state" type="text">
<label for="postcode">Postcode</label>
<input id="postcode" type="text">JavaScript
<script src="https://cdn.ipsofax.com/scripts/ipsofax-autocomplete-1.2.1.js"></script>
<script>
ipsofax.autocomplete('address_line_1', 'DOMAIN TOKEN',
{
dataset: 'nz-linz',
output_fields: {
address_line_1: 'address_line_1',
address_line_2: 'address_line_2',
locality_name: 'suburb',
postcode: 'postcode'
}
});
</script>Try it live on the libraries page.
Dedicated search box
Prefer a search box that completes the lines below it? Bind the widget to that input and choose what the box shows after selection:line1 (default), formatted, or clear.
JavaScript
// A dedicated search box above the address fields
ipsofax.autocomplete('address_search', 'DOMAIN TOKEN', {
dataset: 'nz-linz',
search_display: 'formatted', // show the full resolved label in the box
output_fields: {
address_line_1: 'address_line_1',
address_line_2: 'address_line_2',
locality_name: 'suburb',
state: 'state',
postcode: 'postcode'
}
});Postcode lookup
A structured alternative to type-ahead: pass the 4-digit postcode and, optionally, a street and premise (number or building name). You can still use the combined form — 6011MOL 42. Listing is free; resolving the chosen address costs 1 credit.
JavaScript
const { addresses } = await ipsofax.postcodeLookup({
postcode: '6011',
street: 'MOL', // optional
premise: '42', // optional
}, 'DOMAIN TOKEN', { dataset: 'nz-linz', limit: 25 });
for (const a of addresses) console.log(a.formatted); // free
const picked = await ipsofax.resolve(addresses[0].id, 'DOMAIN TOKEN', { dataset: 'nz-linz' }); // 1 creditReverse geocoding
nearest() returns the closest addresses to a point, nearest first with distance in metres. One credit when addresses come back; nothing nearby is free.
JavaScript
const { results } = await ipsofax.nearest(
-41.2866, 174.7756, 'DOMAIN TOKEN', { dataset: 'nz-linz', limit: 5 });
for (const a of results)
console.log(a.distance_m + ' m', a.formatted); // 1 creditOptions
| Option | Default | Description |
|---|---|---|
| output_fields | — | Map of Ipsofax field → your form field (id or name). |
| baseUrl | same origin | API base, e.g. https://api.ipsofax.com or http://localhost:8080 for the local gateway. |
| dataset | nz-linz | Dataset code; pass it explicitly for each request. |
| country | — | Optional country shorthand; wins over dataset. |
| limit | 8 | Suggestions per request (1–25). |
| minLength | 2 | Characters before searching. |
| debounceMs | 150 | Keystroke settling time. |
| search_display | line1 | line1 | formatted | clear — what the bound input shows after a pick. |
| placeholder | — | Hint text for the search input. |
| on_select | — | function(resolveResponse, suggestion) after a successful resolution. |
| on_error | — | function(message) on network/API errors. |
| autoFocus | false | Focus the bound input on init. |
Output fields
Keys on the left are what the widget writes; values are your form field ids or names. Fields a dataset does not have (e.g. state in NZ) are left untouched.
| Key | Value | Notes |
|---|---|---|
| address_line_1 | number + street | e.g. “1 QUEEN STREET” |
| address_line_2 | unit / building | sub_building_name, else building_name |
| locality_name, locality | suburb / town | |
| dependent_locality | suburb / dependent locality | when the dataset has one |
| street, building_number, building_name, sub_building_name | parts | |
| state | state / region | when the dataset has one |
| postcode | postcode | four digits |
| address_id | dataset id | LINZ id for New Zealand |
| formatted | full label | comma-joined, for inputs |
| label | structured label | dataset-correct lines + locality / dependent_locality / state / postcode; no separators |
| latitude, longitude | geocode | when the dataset has one |
What is charged
- Typing (
/v1/<dataset>/suggest) — free, rate limited. - Selecting a concrete address (
/v1/<dataset>/resolve) — 1 credit. - Selecting a street/locality grouping — free; it just completes the label.
See what is a lookup? for the full model.
Accessibility & devices
The bound input is an ARIA combobox (listbox popup, active descendant). Keyboard: ↓/↑ to move, Enter to select, Esc to close. The dropdown is fixed-positioned so it survives scrollable layouts, and rows are full-width for touch.
Errors
Network or API errors are shown inside the dropdown; wire on_error to log or instrument them. Nothing throws into your page.
Versioning
The filename carries the version (ipsofax-autocomplete-1.2.1.js) so you can pin an exact build. New releases add new files; old URLs keep working.
Attribution
- NZ results: “NZ Addresses © Toitū Te Whenua LINZ” (CC BY 4.0).