1.3.5 • Published 2 years ago

postcode-lookup-psl v1.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm

postcode-lookup-psl

A small library for an easy Postcode address lookup implementation by Paloma staff

Install

NPM

npm i postcode-lookup-psl

CDN

<link rel="stylesheet" href="https://unpkg.com/postcode-lookup-psl/dist/index.min.css">
<script src="https://unpkg.com/postcode-lookup-psl/dist/index.min.js"></script>

Usage

index.html

<input class="txtPostcode" type="text">
<input class="txtAddress1" type="text">
<input class="txtAddress2" type="text">
<input class="txtAddress3" type="text">
<input class="txtTown" type="text">
<input class="txtCounty" type="text">
<select class="ddlCountry">
</select>

index.js

import { postcodeLookup, checkAddressListExists } from 'postcode-lookup-psl'

window.onload = function () {
    postcodeLookupInit();
};


const postcodeLookupInit = async () => {
    const txtPostcode = document.querySelector(".txtPostcode");
    txtPostcode.addEventListener('keyup', async () => {
        // Creates divAddressList if it doesn't already exist
        let divAddressList = checkAddressListExists(txtPostcode);

        divAddressList.appendChild(
            await postcodeLookup({
            postcode: txtPostcode.value.toString(),
            api_key: 'my_api_key',
            provider: 'my_postcode_lookup_provider
            })
        )
    });
}

If any of the fields listed are not found on the page then the value (when selected from the address list) are stored in a cookie so it can still be accessed.

Options

OptionTypeDefaultDescription
PostcodestringnullThe postcode to retrieve
api_keystringnullYour postcode provider API key
providerstringnullYour postcode provider
addDisplayLabelbooelanfalseWhen turned on this will append a label beneath the postcode field with the selected address. Use this option when the address fields are not visibly populated.
classNamesObjectnullAn object of selectors for identifying address fields (see class name table below)

classNames

OptionTypeDefaultDescription
postcodestringtxtPostcodeThe selector for the postcode field
addressLine1txtAddress1nullThe selector for the address line 1 field
addressLine2txtAddress2nullThe selector for the address line 2 field
addressLine3txtAddress3falseThe selector for the address line 3 field
townstringtxtTownThe selector for the town field
countystringtxtCountyThe selector for the county field
countrystringddlCountryThe selector for the country field
1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago