Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Or this:
[searchCountryFlag]="true"
[searchCountryField]="[SearchCountryField.Iso2, SearchCountryField.Name]"
[selectFirstCountry]="false"
[selectedCountryISO]="CountryISO.India"
[selectedCountryCode]="CountryISO.India"
[maxLength]="15"
[phoneValidation]="true"
[inputId]="my-input-id"
Expand Down Expand Up @@ -116,7 +116,7 @@ Or this:
| selectFirstCountry | `boolean` | `true` | Selects first country from `preferredCountries` if is set. If not then uses main list. |
| phoneValidation | `boolean` | `true` | Disable phone validation. |
| inputId | `string` | `phone` | Unique ID for `<input>` element. |
| selectedCountryISO | `<CountryISO>` | `None` | Set specific country on load. |
| selectedCountryCode | `string (<CountryISO> or 'dial code' )` | `None` | Set specific country on load. |
| separateDialCode | `boolean` | `false` | Visually separate dialcode into the drop down element. |
| countryChange | `<Country>` | `None` | Emits country value when the user selects a country from the dropdown. |

Expand Down
65 changes: 33 additions & 32 deletions projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as lpn from 'google-libphonenumber';

import {
Component,
ElementRef,
EventEmitter,
forwardRef,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
ViewChild,
Component,
ElementRef,
EventEmitter,
forwardRef,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
ViewChild,
} from '@angular/core';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';

Expand All @@ -25,24 +25,24 @@ import { phoneNumberValidator } from './ngx-intl-tel-input.validator';
import { PhoneNumberFormat } from './enums/phone-number-format.enum';

@Component({
// tslint:disable-next-line: component-selector
selector: 'ngx-intl-tel-input',
templateUrl: './ngx-intl-tel-input.component.html',
styleUrls: ['./bootstrap-dropdown.css', './ngx-intl-tel-input.component.css'],
providers: [
CountryCode,
{
provide: NG_VALUE_ACCESSOR,
// tslint:disable-next-line:no-forward-ref
useExisting: forwardRef(() => NgxIntlTelInputComponent),
multi: true,
},
{
provide: NG_VALIDATORS,
useValue: phoneNumberValidator,
multi: true,
},
],
// tslint:disable-next-line: component-selector
selector: 'ngx-intl-tel-input',
templateUrl: './ngx-intl-tel-input.component.html',
styleUrls: ['./bootstrap-dropdown.css', './ngx-intl-tel-input.component.css'],
providers: [
CountryCode,
{
provide: NG_VALUE_ACCESSOR,
// tslint:disable-next-line:no-forward-ref
useExisting: forwardRef(() => NgxIntlTelInputComponent),
multi: true,
},
{
provide: NG_VALIDATORS,
useValue: phoneNumberValidator,
multi: true,
},
],
})
export class NgxIntlTelInputComponent implements OnInit, OnChanges {
@Input() value = '';
Expand All @@ -58,7 +58,7 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
@Input() searchCountryPlaceholder = 'Search Country';
@Input() maxLength = '';
@Input() selectFirstCountry = true;
@Input() selectedCountryISO: CountryISO;
@Input() selectedCountryCode: string;
@Input() phoneValidation = true;
@Input() inputId = 'phone';
@Input() separateDialCode = false;
Expand Down Expand Up @@ -102,7 +102,7 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
}

ngOnChanges(changes: SimpleChanges) {
const selectedISO = changes['selectedCountryISO'];
const selectedISO = changes['selectedCountryCode'];
if (
this.allCountries &&
selectedISO &&
Expand Down Expand Up @@ -519,9 +519,10 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
* Updates selectedCountry.
*/
private updateSelectedCountry() {
if (this.selectedCountryISO) {
if (this.selectedCountryCode) {
this.selectedCountry = this.allCountries.find((c) => {
return c.iso2.toLowerCase() === this.selectedCountryISO.toLowerCase();
return ((c.iso2.toLowerCase() === this.selectedCountryCode.toLowerCase()) ||
(c.dialCode.toLowerCase() === this.selectedCountryCode.toLowerCase()));
});
if (this.selectedCountry) {
if (this.phoneNumber) {
Expand Down