Code Monkey home page Code Monkey logo

citynameautocomplete's Introduction

CityNameAutocomplete

Assists input of city name in registration or checkout form. When user enters a few characters it shows a dropdown with city variants. It's possible to select a variant by either clicking on it or by navigations with keyboard arrows and pressing enter. When selected a variant will be copied to the input field of city name.

Installation

In order to pull the latest version:

npm (preferred)

npm i @endereco/citynameautocomplete

github

git clone https://github.com/Endereco/CityNameAutocomplete.git

Then include CityNameAutocomplete.js in <header> or before config.

Configuration

In order to use city name autocomplete you must specify the fields that make the postcode, city name and country, and some colors.

Here is an example configuration:

new CityNameAutocomplete({
    'inputSelector': 'input[name="register[billing][city]"]',
    'secondaryInputSelectors': {
        'postCode': 'input[name="register[billing][zipcode]"]',
        'country': 'select[name="register[billing][country]"]'
    },
    'endpoint': 'https://example-domain.com/endpoint',
    'apiKey': '041c3c302746cf37722560a7a285690738a7db4e55b7aaf26a545ffabd318a83',
    'colors' : {
       'primaryColor' => '#fff',
       'primaryColorHover' => '#fff',
       'primaryColorText' => '#fff',
       'secondaryColor' => '#fff',
       'secondaryColorHover' => '#fff',
       'secondaryColorText' => '#fff',
       'warningColor' => '#fff',
       'warningColorHover' => '#fff',
       'warningColorText' => '#fff',
       'successColor' => '#fff',
       'successColorHover' => '#fff',
       'successColorText' => '#fff'
   }
});

Dependencies

CityNameAutocomplete relies on StatusIndicator to mark fields green on correct input.

CityNameAutocomplete also relies on Accounting to generate the tid and track transactions.

Methods

updateConfig(object newConfig)

Updates inner config. Existing fields are overwritten, new fields are added, other field are kept.

checkIfFieldsAreSet()

Checks if all relevant fields are set and marks the service as "dirty", if there was a change. Dirty state trigger reinitialisation.

getPredictions()

Get a list of possible city names and eventually postcodes for the provided input. Returns a promise that is resolved once the answer from remote server is in.

renderDropdown()

Renders the autocomplete list.

removeDropdown()

Removes autocomplete list from DOM.

citynameautocomplete's People

Contributors

chartechlabs avatar endereco avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.