Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hof-behaviour-address-lookup

Package Overview
Dependencies
Maintainers
14
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hof-behaviour-address-lookup

A HOF Behaviour for a multi-step postcode lookup

  • 2.2.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
14
Weekly downloads
 
Created
Source

hof-behaviour-address-lookup

A HOF Behaviour for controlling a multi-step address lookup.

Usage

// steps.js

const AddressLookup = require('hof-behaviour-address-lookup');

module.exports = {
  '/step-1' {
    behaviours: AddressLookup({
      addressKey: 'address-field'
    })
  }
}

Options

  • addressKey - REQUIRED - the key used to store the formatted address after lookup
  • required - if set to a truthy value then the address is required. By default a user can pass through without entering an address.
  • apiSettings - settings to pass to the Model on init. Default MOJ lookup api expects hostname, authorization, paths.lookup and paths.validate
  • Model - a custom Model which exposes a fetch method (and validate if using api validation). Both fetch and validate are expected to return a Promise
  • validate - a map of validators to pass to the Model's validate method. The default implementation supports allowedCountries which is an Array of accepted countries. - for only English addresses use:
AddressLookup({
  addressKey: 'address',
  validate: {
    allowedCountries: ['England']
  }
});

Custom Model Integration

If you provide a custom model, you should provide a fetch method which returns a Promise and resolves with the data on a successful lookup, and rejects with an Error if the service is unavailable. In the case of the service being unavailable a message is shown and a textarea is shown for the address to be input manually.

When providing a custom validate function, this should also return a Promise which resolves on a success validation, and rejects with an error with status 418 if validation fails.

Locales

The following keys are expected to be defined in your translations file.

  • pages.address-lookup.edit - text to change the postcode once entered. Defaults to 'Change';
  • pages.address-lookup.cantfind - link text for manual entry if you cant find your address in the lookup. Defaults to 'I can\'t find the address in the list'
  • fields.{key}-postcode.label - Label for the postcode field when shown on the lookup and manual steps. Defaults to 'Postcode'
  • pages.address-lookup.postcode-api.not-found - Message to show if postcode not found. Defaults to 'Sorry – we couldn’t find any addresses for that postcode, enter your address manually'
  • pages.address-lookup.postcode-api.cant-connect - Message to show if unable to connect to the lookup service. Defaults to 'Sorry – we couldn’t connect to the postcode lookup service at this time, enter your address manually'
  • buttons.find-address - Postcode submit button text. Required.

FAQs

Package last updated on 04 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc