Skip to content

Commit

Permalink
Fix country updating bugs and add missing dial codes
Browse files Browse the repository at this point in the history
Fix NPE when changing flags with an invalid country code input
Fix flag being wrongly updated for duplicate dial codes
Add missing dialing codes
  • Loading branch information
Priit Danelson committed Feb 19, 2018
1 parent fe43089 commit c845022
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class IntPhonePrefixComponent implements OnInit, ControlValueAccessor {
private updatePhoneInput(countryCode: string) {
this.showDropdown = false;

let newInputValue: string = IntPhonePrefixComponent.startsWithPlus(this.phoneInput)
let newInputValue: string = IntPhonePrefixComponent.startsWithPlus(this.phoneInput) && this.selectedCountry
? `${this.phoneInput.split(PLUS)[1].substr(this.selectedCountry.dialCode.length, this.phoneInput.length)}`
: this.phoneInput;

Expand All @@ -157,9 +157,13 @@ export class IntPhonePrefixComponent implements OnInit, ControlValueAccessor {

private findPrefix(prefix: string) {
let foundPrefixes: Country[] = this.countries.filter((country: Country) => prefix.startsWith(country.dialCode));
this.selectedCountry = !_.isEmpty(foundPrefixes)
let selectedPrefix: Country = !_.isEmpty(foundPrefixes)
? IntPhonePrefixComponent.reducePrefixes(foundPrefixes)
: null;
if (selectedPrefix && this.selectedCountry && selectedPrefix.dialCode === this.selectedCountry.dialCode) {
return;
}
this.selectedCountry = selectedPrefix;
}

private updateValue() {
Expand Down
107 changes: 106 additions & 1 deletion src/lib/src/service/country.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from '@angular/core';
import {Country} from "../interface/country.interface";
import {Country} from '../interface/country.interface';

@Injectable()
export class CountryService {
Expand Down Expand Up @@ -1147,6 +1147,111 @@ export class CountryService {
name: '',
dialCode: '358',
countryCode: 'ax'
},
{
name: '',
dialCode: '93',
countryCode: 'af'
},
{
name: '',
dialCode: '355',
countryCode: 'al'
},
{
name: '',
dialCode: '213',
countryCode: 'dz'
},
{
name: '',
dialCode: '1684',
countryCode: 'as'
},
{
name: '',
dialCode: '376',
countryCode: 'ad'
},
{
name: '',
dialCode: '244',
countryCode: 'ao'
},
{
name: '',
dialCode: '1264',
countryCode: 'ai'
},
{
name: '',
dialCode: '672',
countryCode: 'aq'
},
{
name: '',
dialCode: '1268',
countryCode: 'ag'
},
{
name: '',
dialCode: '54',
countryCode: 'ar'
},
{
name: '',
dialCode: '374',
countryCode: 'am'
},
{
name: '',
dialCode: '297',
countryCode: 'aw'
},
{
name: '',
dialCode: '61',
countryCode: 'au'
},
{
name: '',
dialCode: '43',
countryCode: 'at'
},
{
name: '',
dialCode: '55',
countryCode: 'bv'
},
{
name: '',
dialCode: '262',
countryCode: 'tf'
},
{
name: '',
dialCode: '6723',
countryCode: 'hm'
},
{
name: '',
dialCode: '599',
countryCode: 'an'
},
{
name: '',
dialCode: '64',
countryCode: 'pn'
},
{
name: '',
dialCode: '500',
countryCode: 'gs'
},
{
name: '',
dialCode: '699',
countryCode: 'um'
}
];
}
Expand Down

0 comments on commit c845022

Please sign in to comment.