ngx-international-phone-number icon indicating copy to clipboard operation
ngx-international-phone-number copied to clipboard

Phone fields adjustments

Open khaledayed opened this issue 5 years ago • 0 comments

I'm using the ngx international phone number library in my Angular 8 project and I want to set the country code to readonly. I found this solution: <international-phone-number (keydown)="testInput($event)" name="phone_number" placeholder="Enter phone number" [maxlength]="20" [defaultCountry]="'sg'" [required]="true" #phoneNumber="ngModel" name="phone_number" [allowedCountries]="['sg']"></international-phone-number> The example uses a Singapore country code. I have used the keydown event and I am checking the last position of the country code. If I have a country code of +65 then I am considering selectionStart greater than/equal to 3`. This is the code in a ts file:

testInput(event) 
{ 
  if (!(event.target.selectionStart >= 3) || (event.target.selectionStart < 4 && event.key === 'Backspace')) 
  {
    event.stopPropagation();
    event.preventDefault();
  }
}```
The problem is I just want to make this function work for all types of country codes

khaledayed avatar Jan 23 '20 21:01 khaledayed