From c84502213b5ce4d9959db89ae9068c0413bc3be1 Mon Sep 17 00:00:00 2001 From: Priit Danelson Date: Fri, 16 Feb 2018 17:31:00 +0200 Subject: [PATCH] Fix country updating bugs and add missing dial codes Fix NPE when changing flags with an invalid country code input Fix flag being wrongly updated for duplicate dial codes Add missing dialing codes --- .../int-phone-prefix.component.ts | 8 +- src/lib/src/service/country.service.ts | 107 +++++++++++++++++- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/src/lib/src/component/int-phone-prefix/int-phone-prefix.component.ts b/src/lib/src/component/int-phone-prefix/int-phone-prefix.component.ts index b1e3a8e..3ff9bc6 100644 --- a/src/lib/src/component/int-phone-prefix/int-phone-prefix.component.ts +++ b/src/lib/src/component/int-phone-prefix/int-phone-prefix.component.ts @@ -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; @@ -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() { diff --git a/src/lib/src/service/country.service.ts b/src/lib/src/service/country.service.ts index 8e02cac..f556615 100644 --- a/src/lib/src/service/country.service.ts +++ b/src/lib/src/service/country.service.ts @@ -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 { @@ -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' } ]; }