Skip to content

Commit

Permalink
fixed initial validity state
Browse files Browse the repository at this point in the history
  • Loading branch information
mareczek committed Aug 26, 2015
1 parent 6514e87 commit 7bf5c90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
26 changes: 5 additions & 21 deletions releases/international-phone-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@
ctrl.$formatters.push(function(value) {
if (!value) {
return value;
} else {
$timeout(function() {
return element.intlTelInput('setNumber', value);
}, 0);
return element.val();
}
element.intlTelInput('setNumber', value);
return element.val();
});
ctrl.$parsers.push(function(value) {
if (!value) {
Expand All @@ -86,23 +83,10 @@
return value.replace(/[^\d]/g, '');
});
ctrl.$validators.internationalPhoneNumber = function(value) {
if (element.attr('required')) {
if (!value) {
return false;
} else {
return element.intlTelInput("isValidNumber");
}
} else {
if (element.intlTelInput("getSelectedCountryData").dialCode === value) {
return true;
} else {
if (!value) {
return true;
} else {
return element.intlTelInput("isValidNumber");
}
}
if (!value) {
return true;
}
return element.intlTelInput("isValidNumber");
};
element.on('blur keyup change', function(event) {
return scope.$apply(read);
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.

28 changes: 9 additions & 19 deletions src/international-phone-number.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,21 @@ angular.module("internationalPhoneNumber", []).directive 'internationalPhoneNumb
ctrl.$formatters.push (value) ->
if !value
return value
else
$timeout () ->
element.intlTelInput 'setNumber', value
, 0
return element.val()

element.intlTelInput 'setNumber', value
element.val()

ctrl.$parsers.push (value) ->
return value if !value
if !value
return value

value.replace(/[^\d]/g, '')

ctrl.$validators.internationalPhoneNumber = (value) ->
if element.attr('required')
if !value
return false
else
return element.intlTelInput("isValidNumber")
else
if element.intlTelInput("getSelectedCountryData").dialCode == value
return true
else
if !value
return true
else
return element.intlTelInput("isValidNumber")
if !value
return true

element.intlTelInput("isValidNumber")

element.on 'blur keyup change', (event) ->
scope.$apply read
Expand Down

0 comments on commit 7bf5c90

Please sign in to comment.