Skip to content

Commit

Permalink
Merge pull request #79 from skfd/feature-bind-country
Browse files Browse the repository at this point in the history
Feature bind country
  • Loading branch information
mareczek committed Nov 23, 2015
2 parents 7cbb478 + 044ab48 commit afe9925
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
international-phone-number
==========================

AngularJS directive implementing intl-tel-input (https://github.com/Bluefieldscom/intl-tel-input) jQuery plugin.
AngularJS directive implementing [intl-tel-input](https://github.com/Bluefieldscom/intl-tel-input) jQuery plugin.

Installation
--
Expand All @@ -15,11 +15,11 @@ intl-tel-input is installed as a dependency. Make sure `intTelInput.js` is loade

You can optionally include `bower_components/intl-tel-input/lib/libphonenumber/build/utils.js`.

DEMO
DEMOS
--
Provided by skfd: http://plnkr.co/edit/DYyfGj?p=preview
[Plunkr](http://plnkr.co/edit/DYyfGj?p=preview)

Available from souce project at http://jackocnr.com/intl-tel-input.html
[int-tel-input jQuery plugin demo](http://jackocnr.com/intl-tel-input.html)


Default options
Expand Down Expand Up @@ -64,6 +64,11 @@ NgModel is required
<input type="text" international-phone-number ng-model="phone">
```

with bound country. Useful when you have external contries control:
```html
<input type="text" international-phone-number only-countries ng-model="phone" country="country">
```

with preferred countries:
```html
<input type="text" international-phone-number preferred-countries="pl, de" ng-model="phone">
Expand All @@ -74,7 +79,7 @@ with default country:
<input type="text" international-phone-number default-country="pl" ng-model="phone">
```

with only countries:
with countries only:
```html
<input type="text" international-phone-number only-countries ng-model="phone">
```
Expand Down
8 changes: 7 additions & 1 deletion releases/international-phone-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
restrict: 'A',
require: '^ngModel',
scope: {
ngModel: '='
ngModel: '=',
country: '='
},
link: function(scope, element, attrs, ctrl) {
var handleWhatsSupposedToBeAnArray, options, read, watchOnce;
Expand Down Expand Up @@ -73,6 +74,11 @@
return watchOnce();
});
});
scope.$watch('country', function(newValue) {
if (newValue !== null && newValue !== void 0 && newValue !== '') {
return element.intlTelInput("selectCountry", newValue);
}
});
ctrl.$formatters.push(function(value) {
if (!value) {
return value;
Expand Down
4 changes: 2 additions & 2 deletions releases/international-phone-number.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/international-phone-number.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ angular.module("internationalPhoneNumber", [])
require: '^ngModel'
scope:
ngModel: '='
country: '='

link: (scope, element, attrs, ctrl) ->

Expand Down Expand Up @@ -80,7 +81,11 @@ angular.module("internationalPhoneNumber", [])
watchOnce()

)


scope.$watch('country', (newValue) ->
if newValue != null && newValue != undefined && newValue != ''
element.intlTelInput("selectCountry", newValue)
)

ctrl.$formatters.push (value) ->
if !value
Expand Down

0 comments on commit afe9925

Please sign in to comment.