react-phone-number-input: Error when countryCallingCodeEditable={false} and value is empty
Error when countryCallingCodeEditable={false} and initial value is undefined. The first country is selected by default in country select, but the code is not applied. When you try to type some value into input, it is not possible and you get the error “Unknown country: undefined”
const [value, setValue] = useState();
<PhoneInput
value={value}
onChange={setValue}
international
countryCallingCodeEditable={false}
/>
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
@Jack-Barry I see. Published
react-phone-number-input@3.2.22
@catamphetamine Think I’ve tracked down where our country gets set to
undefined
When
getCountryFromPossiblyIncompleteInternationalPhoneNumber
is called with a number like+15555555555
, it returnsundefined
. This happens here: https://github.com/catamphetamine/react-phone-number-input/blob/708f2cdbadff074fd9755b15fcdf1792421363e3/source/helpers/phoneInputHelpers.js#L371Is there some other format that the number has to be in for it to be parsed and return an inferred country?
I could be reading it wrong, but from what I can tell it would have to be passed in as a National (significant) number, so the
+1
would have to be dropped,5555555555
. I don’t think there’s a clean way to do chop that prefix off here thoughMaybe it was a bug. See if the latest version works. Your sandbox uses an older version.