justin-lau / ember-intl-tel-input

An Ember.js addon for entering and validating international telephone numbers.
http://justin-lau.github.io/ember-intl-tel-input/
MIT License
21 stars 36 forks source link

ember-intl-tel-input

Build Status npm version Dependency Status devDependency Status

An Ember.js addon for entering and validating international telephone numbers.

Please check out the demo page to see the addon in action.

For more information on using ember-cli, visit http://www.ember-cli.com/.

Installation

$ ember install ember-intl-tel-input

Basic Usage

Just place the {{intl-tel-input}} component in the handlebars template, as you would have guessed.

{{intl-tel-input}}

The component derives from Ember.TextField, anything you can do with the input helper can also be done with this component.

{{intl-tel-input value="555-5555"}}

With Utilities Script

With the utilities script included, the autoFormat and autoPlaceholder options are automatically enabled.

// ember-cli-build.js
module.exports = function(defaults) {
  var app = new EmberAddon(defaults, {
    intlTelInput: {
      includeUtilsScript: true, // default to false
    },
  });
};
{{intl-tel-input}}

Properties Binding

Use the following properties for binding:

{{intl-tel-input
  allowExtensions=true
  value=value
  selectedCountryData=selectedCountryData
  number=number
  extension=extension
  numberType=numberType
  isValidNumber=isValidNumber
  validationError=validationError}}

Lookup User's Country

intl-tel-input provides a convenient way to look up the user's country based on their IP addresses. This example uses Telize for demonstration.

// controller

geoIpLookupFunc: function(callback) {
  $.getJSON('//www.telize.com/geoip')
   .always(function(resp) {
     if (!resp || !resp.country_code) {
       callback('');
     }

     callback(resp.country_code);
   });
}
{{intl-tel-input
  defaultCountry="auto"
  geoIpLookup=geoIpLookupFunc}}

Running The Demo Page Locally

Run ember server, and visit the demo page at http://localhost:4200.

Credits

This is a wrapper library. It simply wraps the API of the original jQuery plugin created by Jack O'Connor into an Ember.js component.

The original jQuery plugin also depends on several other open-source libraries:

This addon's demo page uses Telize for a fast, SSL-supported, yet FREE Geo IP service.

Telize no longer provide free services due to heavy abuse. The demo has switched over to ipinfo.io.

The layout and color theme of the demo page comes from Twitter's Bootstrap and Ember.js, respectively.