phone input: fix set country with empty input
This commit is contained in:
@@ -187,9 +187,11 @@
|
||||
if (!e.target) return;
|
||||
const input = e.target as HTMLInputElement;
|
||||
|
||||
// Format the input string
|
||||
const formatter = new AsYouType(formatterCountryCode);
|
||||
const formatted = formatter.input(input.value);
|
||||
|
||||
// If the input length is greater than the last value, use formatted text
|
||||
if (input.value.length >= lastRawValue.length) {
|
||||
setTimeout(() => {
|
||||
input.value = formatted;
|
||||
@@ -197,13 +199,18 @@
|
||||
}
|
||||
lastValue = formatter.getNumber();
|
||||
|
||||
if (formatter.isValid() && formatter.isInternational() && value) {
|
||||
// If we have a valid international number, update the country
|
||||
if (formatter.isValid() && formatter.isInternational()) {
|
||||
const country = formatter.getCountry();
|
||||
if (country) {
|
||||
setCountryByISO(country);
|
||||
setTimeout(() => {
|
||||
if (lastValue) input.value = lastValue.formatNational();
|
||||
}, 1);
|
||||
|
||||
// If the phone value has been set before, update it with the new value
|
||||
if (value) {
|
||||
setTimeout(() => {
|
||||
if (lastValue) input.value = lastValue.formatNational();
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user