react-phone-input-2 icon indicating copy to clipboard operation
react-phone-input-2 copied to clipboard

Chrome autocomplete not working well

Open Lapro15 opened this issue 6 years ago • 5 comments

Hello, Following the integration of your lib, we noticed that the Chrome autocomplete does't work if the prefix linked to the country code is not entered in the saved number of the user. For example, if my number saved in Chrome is 4185555555, a Canadian number, where the prefix 1 is missing, then autocomplete will only add 4185555555 and I will be located in Switzerland. Wrong: image vs Right: image

Lapro15 avatar Oct 30 '20 20:10 Lapro15

Of course the behavior intended by you will not work if the phone number do not have a canadian prefix — it will not have a way to determine the country that you want it to display.

bl00mber avatar Nov 06 '20 03:11 bl00mber

I had the same issue, I got it to work with this workaround.

function handleChange(value, data, event, formattedValue) {
  if (value.length - val.length > 1 && value.length === 10) {
    setVal(`1${value}`);
  } else {
    setVal(value);
  }
}
  
<PhoneInput
  onChange={handleChange}
  ...
/>

where val is a state variable.

Anindya91 avatar Mar 09 '21 23:03 Anindya91

It is not relevant to the topic, but i want to save somewhere my solution. If autocomplete not working, then try to pass field name to inputProps like inputProps={{ name: 'phone' }}

S-Vlad avatar Apr 12 '21 12:04 S-Vlad

passing the countryCodeEditable={true} prop solves this issue for all regions

calumptrck avatar May 19 '22 21:05 calumptrck

Is there a way to make it default to a certain country code if the phone number autofilled is 10 digits?

tatetoussaint avatar Jan 24 '24 05:01 tatetoussaint