Git Product home page Git Product logo

ng-intl-tel-input's Introduction

betsol-ng-intl-tel-input

npm version Bower version

This module for Angular.js (^1.2.29) provides integration for the great intl-tel-input jQuery plugin (version 7-8 are supported).

Please feel free to investigate the original plugin for mode details, features and configuration.

—» DEMO «—

Installation

Install integration library with npm or Bower

  • npm i --save betsol-ng-intl-tel-input

  • bower install --save betsol-ng-intl-tel-input

Add integration library to your page

Make sure, that module is added to your page either as a part of automatically built bundle or manually using the code like this:

<script src="../betsol-ng-intl-tel-input/dist/betsol-ng-intl-tel-input.js"></script>

You should use minified version (betsol-ng-intl-tel-input.min.js) in production.

Add dependency in your application's module definition

var application = angular.module('application', [
  // ...
  'betsol.intlTelInput'
]);

Introduce the directive

To add the plugin to any input field please use the intl-tel-input directive:

<input type="tel" ng-model="user.phoneNumber" intl-tel-input>

Original plugin

This module depends on intl-tel-input plugin to operate. If you installed the module using npm or Bower, then the dependency will be installed automatically, and if your are using some automated build tool, it will probably be added to your bundle.

In other cases make sure to install it manually using the following guide.

Configuration

Global

You can configure the plugin by changing the global object intlTelInputOptions. This will apply specified changes across all plugin instances in your application. All configuration options could be found in the original plugin documentation.

Global Configuration Example

angular
  .module('app', ['betsol.intlTelInput'])
  .config(function (intlTelInputOptions) {
    angular.extend(intlTelInputOptions, {
      nationalMode: false,
      utilsScript: '/vendor/intl-tel-input/utils.js',
      defaultCountry: 'auto',
      preferredCountries: ['ru', 'kz'],
      autoFormat: true,
      autoPlaceholder: true
    });
  })
;

Custom instance configuration

You can configure each input field individually by specifying the configuration options via intl-tel-input-options attribute.

Instance Configuration Example

<input
    type="tel"
    ng-model="user.phoneNumber"
    intl-tel-input
    intl-tel-input-options="{ excludeCountries: ['us', 'de'] }"
>

API

You can use intl-tel-input-controller attribute to specify an object that will be populated with the directive's API functions.

API Usage Example

angular
  .module('app', ['betsol.intlTelInput'])
  .controller('MyCtrl', function ($scope) {
    $scope.myIntlTelInputCtrl;
    $scope.changeCountryToRussia = function () {
      $scope.myIntlTelInputCtrl.setCountry('ru');
    };
  })
;
<input
    type="tel"
    ng-model="user.phoneNumber"
    intl-tel-input
    intl-tel-input-controller="myIntlTelInputCtrl"
>
<button ng-click="changeCountryToRussia()">
    Change Country to Russia
</button>

List of Supported API Functions:

  • setCountry({string} countryCode)

Phone number validator

This directive will add phoneNumber validator to the underlying model controller. You can use it to display validation errors.

Validation Example

<span ng-show="formName.inputName.$error.phoneNumber">
    Please enter a correct phone number!
</span>

Changelog

Please see the changelog for list of changes.

Feedback

If you have found a bug or have another issue with the library — please create an issue.

If you have a question regarding the library or it's integration with your project — consider asking a question at StackOverflow and sending me a link via E-Mail. I will be glad to help.

Have any ideas or propositions? Feel free to contact me by E-Mail.

Cheers!

FAQ

@todo

Developer guide

Fork, clone, create a feature branch, implement your feature, cover it with tests, commit, create a PR.

Run:

  • npm i to initialize the project
  • npm i -g gulp to install Gulp
  • gulp build to re-build the dist files
  • gulp test or karma start to test the code
  • gulp start to run demo server and watches
  • gulp demo:deploy to deploy the demo on GitHub Pages

Do not add dist files to the PR itself. We will re-compile the module manually each time before releasing.

Support

If you like this library consider to add star on GitHub repository.

Thank you!

License

The MIT License (MIT)

Copyright (c) 2016 Slava Fomin II, BETTER SOLUTIONS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ng-intl-tel-input's People

Contributors

jordandotme avatar yiuminghuynh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ng-intl-tel-input's Issues

Get countries list for select input

Hi all,
I need to make an input with country codes to choose default country code for user customization.
Anybody knows how can I do that with this plugin?

Library not compatible with jQuery v3 ^

betsol/ng-intl-tel-input cannot be used with jQuery v3 and later.

Some functions in dependency intl-tel-input v7.1.1 - 8* are not compatible with jQuery version 3 and above. This is because the original intl-tel-input library uses deprecated function $(window).load(function() { ... }); in versions v7.1.1 - 8* instead of its newer counterpart, $(window).on('load', function() { ... });

This has been fixed in v9 ^ of intl-tel-input.

If permitting, updating the bower.json file for betsol/ng-intl-tel-input to specify v9 intl-tel-input would solve this problem.

Update to v9?

intl-tel-input is now at 9.0.7. Any chance on getting this updated to work with v9?

Failed to instantiate module due to main path in bower file

In bower.json the following path causes an instantiation error:

"main": "dist/betsol-ng-intl-tel-input.js"

I'm using gulp inject to automatically populate any bower script dependencies. It seems that the above line doesn't work unless I point it to the scripts directory within dist, like so:

``"main": "dist/scripts/betsol-ng-intl-tel-input.js"`

Have you ever had any issues regarding this?

display as filter ?

Hi there !

Is there a way to use your directive as a filter to display formated phone number in paragraph for example:

<p>{{phone | phone}}</p>

?

Non-Assignable error in directive

I receive the following error when using the directive:

Expression 'undefined' used with directive 'intlTelInput' is non-assignable!

Following this document, it seems the issue is in the scope properties:

scope: {
    intlTelInputOptions: '=',
    intlTelInputController: '='
}

Making the binding optional fixes the error:

scope: {
    intlTelInputOptions: '=?',
    intlTelInputController: '=?'
}

Can you confirm that this is a viable solution? If I can configure the module globally, It makes sense to make them optional.

getNumber return empty string

Hi,
I've got an issue with $element.intlTelInput('getNumber') which return an empty string instead of my model.

Working, while adding $timeout to the method getModelValue()

          function getModelValue () {
            $timeout(function() {
              return $element.intlTelInput('getNumber');
            });
          }

Webpack build not working

I'm in the process of migrating to webpack from a Grunt build system that simply places this library along with its dependencies (jQuery, intl-tel-input, utils.js) into a concatenated JS file and then loads it on the page with a <script> tag. Since I'm trying to use the path of least resistance during this migration, I've decided to use the script-loader which loads JS files as if they were loaded via a <script> tag.

I can verify that jQuery, intl-tel-input plugin, utils.js and the ng-intl-tel-input module have all loaded on the page, but when the ng-intl-tel-input directive tries to initialize in the link function, I keep getting the error ng-intl-tel-input: intl-tel-input jQuery plugin must be loaded, skipping directive initialization.

Here is the relevant portion of my app.js entry file that loads the aforementioned scripts:

require("script!../../node_modules/jquery/dist/jquery.js");
...
require("script!../../node_modules/intl-tel-input/build/js/intlTelInput.js");
require("script!../../node_modules/intl-tel-input/build/js/utils.js");
...
require("betsol-ng-intl-tel-input");
...
angular.module("app", ["betsol.intlTelInput"]);

Has anyone else successfully implemented this module using a webpack build system? I know these files work because I can manually load them on the page with <script> tags and the directive functions correctly.

Demo not working correctly?

I noticed the following when testing your demo:
Using the 2nd Set to button of +79031234567 ext. 123, the show National Number button alerts this: "8 (903) 123-45-67 ext. 123" Dont know where the first 8 is coming from? Even more interesting since the first sample number +380441234567 returns "044 123 4567"

ng-Model not populating the value

I'm using this module inside an ng-if condition.

I have used ng-model="model.phoneNumber", I still get an undefined as value.
Also when I set the intl-tel-input-controller="myIntlTelInputCtrl" and in controller I have $scope.myIntlTelInputCtrl; I get "getNumber()" of undefined as the API is not getting initialised.

However, intl-tel-input-options="{ onlyCountries: ['us', 'in'] }" is working.

How to use the option "customPlaceholder" ?

Hello,
thank you very much for your directive, it works fine and it very easy to use.
I use many options in my case (nationalMode, allowDropdown, placeholderNumberType...) and it's awesome.
However, I need to customize the placeholder of my field and I don't know how to use the customPlaceholder option ?!

In the library intl-tel-input, he says that's a function...
customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { return "e.g. " + selectedCountryPlaceholder; }

Could you tell me if it's possible to use it with your angularjs directive ?

Thanks in advance

Error: $compile:multidir Multiple Directive Resource Contention

I have created directive in custom componenet and used this ng-intl-tel-input directive in that
and using my custom directive in test page is ok, but in my ionic app with angular it is giving
Error: $compile:multidir Multiple Directive Resource Contention
with below details
Multiple directives [input (module: myionicapp), intlTelInput] asking for new/isolated scope on:

feature request: watching country from somewhere

Hi!

It would be nice to have a shortcut to watch some model or set default country using scope variable like
intl-tel-input-country="some_scope_variable". I found it hard to set country based on another select or data resolved somewhere else.

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.