Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new intl-tel-input-options parameter: "watch", for two-way binding ngModel in realtime & update compatibility for jQuery 3^. #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ You can use it to display validation errors.
</span>
```

### Enabling two-way binding watch for Angular.js (^1.3)

```component template html
<input
type="tel"
ng-model="phoneNumber"
value="{{phoneNumber}}"
id="mobileInput"
intl-tel-input
intl-tel-input-options="{watch:true, ...}"
>
```

## Changelog

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"dependencies": {
"angular": "^1.2.29",
"intl-tel-input": "7.1.1 - 8.*"
"intl-tel-input": "13.0.2"
},
"repository": {
"type": "git",
Expand Down
37 changes: 29 additions & 8 deletions dist/scripts/betsol-ng-intl-tel-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,36 @@

/**
* Validating the input using plugin's API.
*/
*/
if ('undefined' !== typeof modelCtrl.$validators) {
// Using newer `$validators` API.
modelCtrl.$validators[VALIDATOR_NAME] = function (modelValue, viewValue) {
if (!modelValue && !viewValue) {
return true;
if (options.watch){
modelCtrl.$validators[VALIDATOR_NAME] = function (modelValue, viewValue) {
if (!modelValue && !viewValue) {
$element.removeClass('ng-invalid');
$element.addClass('ng-valid');
return true;
}
var isValid = callApi('isValidNumber');
if (isValid){
$element.addClass('ng-valid');
$element.removeClass('ng-invalid');
}
else{
$element.addClass('ng-invalid');
$element.removeClass('ng-valid');
}
return true; //returns model value to two-way binding
}
return isValidInput();
};
}
else{
// Using newer `$validators` API.
modelCtrl.$validators[VALIDATOR_NAME] = function (modelValue, viewValue) {
if (!modelValue && !viewValue) {
return true;
}
return isValidInput();
};
}
} else {
// Using legacy validation approach.
// This is required for Angular v1.2.x.
Expand All @@ -87,7 +108,7 @@
modelCtrl.$parsers.push(validateValue);
modelCtrl.$formatters.push(validateValue);
}

/**
* Destroying the plugin with the directive.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/scripts/betsol-ng-intl-tel-input.min.js

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