npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apostrophe-forms-google-address-field-widgets

v4.1.0

Published

This module adds a Google-based input field validating addresses

Downloads

7

Readme

This module adds a Google-based input field validating addresses. It is meant for use alongside the apostrophe-forms module.

When using it, you must configure the formWidgets option to apostrophe-forms to include it, as well as all other form widgets you wish to use. See the apostrophe-forms documentation.

Configuration

// in app.js
modules: {
  'apostrophe-forms': {
    formWidgets: {
      // other fields go here
      'apostrophe-forms-google-address-field': {}
    }
  },
  'apostrophe-forms-widgets': {},
  'apostrophe-forms-google-address-field-widgets': {
    googleApiKey: 'validGoogleApiKeyHere' // mandatory
  }
}

The user will need a valid Google API key for the suggestions displayed by Google to work as stated in Google Maps Platform documentation: https://developers.google.com/maps/documentation/javascript/places-autocomplete. You must connect a billing account to the Google API console project.

Default rendering:

When submitted, the form's output will contain the input's name and value. For example, if the input's name is address, the above example would output:

{
  address: 'Tour Eiffel, Avenue Anatole France, Paris, France'
}

Advanced settings

The number of results can be restricted

  • to a type (addresses, regions, establishments, ...)
  • to a certain area with coordinates
  • to countries (5 at max due to Google policy)

The address can also be split into multiple fields, as allowed by Google. The current list of choices is the following:

{
  value: 'street_number',
  label: 'Street Number'
},
{
  value: 'route',
  label: 'Route'
},
{
  value: 'locality',
  label: 'City'
},
{
  value: 'sublocality_level_1',
  label: 'City (for NYC area)'
},
{
  value: 'administrative_area_level_1',
  label: 'State'
},
{
  value: 'postal_code',
  label: 'Postal Code'
},
{
  value: 'postal_town',
  label: 'Postal Code (for UK and Sweden)'
},
{
  value: 'country',
  label: 'Country'
}

Broken out fields are displayed by default. They can be hidden through the option "Show Split Address".

Example of a configuration:

Rendering example of the above configuration:

Output

When submitted, the form's output will contain the field name followed by the broken out fields names and values. For example, if the field name is address; the above example would output:

{
  address: 'Tour Eiffel, Avenue Anatole France, Paris, France',
  'address-street_number': '5',
  'address-route': 'Avenue Anatole France',
  'address-locality': 'Paris',
  'address-postal_code': '75007',
  'address-administrative_area_level_1': 'Île-de-France',
  'address-country': 'France'
}

This is what is saved in the database. The object keys come from the package configuration and are the same as Google.

Using multiple Google-based input fields on the same page

It is possible to use multiple Google-based input fields on the same page. Just be sure the names are different. The output will adapt.

For example, if there are 2 fields (one standard named address, the other one in "split" mode named address-2), here is a possible output:

{
  address: 'Tour Eiffel, Avenue Anatole France, Paris, France',
  'address-2': 'Rue de Rivoli, Paris, France',
  'address-2-route': 'Rue de Rivoli',
  'address-2-locality': 'Paris',
  'address-2-administrative_area_level_1': 'Île-de-France',
  'address-2-country': 'France'
}

Labels

In "split" mode, if the broken out fields are displayed, labels will be added to the form. They will contain technical values (street_number, administrative_area_level_1, ...).

In order to display them differently, edit the JSON files in the folder containing the i18n translations (locales at the project level by default).

Example in a en.json file

"street_number": "Street Number",
"route": "Route",
"locality": "City",
"administrative_area_level_1": "State",
"postal_code": "Postal Code",
"country": "Country"