fix: Country code missing when typing in phone input. (#10439)
This commit is contained in:
@@ -114,31 +114,10 @@ function setContextValue(code) {
|
|||||||
context.node.input(localValue.value);
|
context.node.input(localValue.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dynamicallySetCountryCode(value) {
|
|
||||||
const safeValue = unref(value);
|
|
||||||
// This function is used to set the country code dynamically.
|
|
||||||
// The country and dial code is used to set from the value of the phone number field in the pre-chat form.
|
|
||||||
if (!safeValue) return;
|
|
||||||
|
|
||||||
// check the number first four digit and check weather it is available in the countries array or not.
|
|
||||||
const country = countries.value.find(code =>
|
|
||||||
safeValue.startsWith(code.dial_code)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (country) {
|
|
||||||
// if it is available then set the country code and dial code.
|
|
||||||
activeCountryCode.value = country.id;
|
|
||||||
activeDialCode.value = country.dial_code;
|
|
||||||
// set the phone number without dial code.
|
|
||||||
phoneNumber.value = safeValue.replace(country.dial_code, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onChange(e) {
|
function onChange(e) {
|
||||||
phoneNumber.value = e.target.value;
|
phoneNumber.value = e.target.value;
|
||||||
dynamicallySetCountryCode(phoneNumber);
|
|
||||||
// This function is used to set the context value when the user types in the phone number field.
|
// This function is used to set the context value when the user types in the phone number field.
|
||||||
setContextValue(activeDialCode);
|
setContextValue(activeDialCode.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function focusedOrActiveItem(className) {
|
function focusedOrActiveItem(className) {
|
||||||
@@ -157,8 +136,8 @@ function scrollToFocusedOrActiveItem(item) {
|
|||||||
if (focusedOrActiveItemLocal.length > 0) {
|
if (focusedOrActiveItemLocal.length > 0) {
|
||||||
const dropdown = dropdownRef.value;
|
const dropdown = dropdownRef.value;
|
||||||
const dropdownHeight = dropdown.clientHeight;
|
const dropdownHeight = dropdown.clientHeight;
|
||||||
const itemTop = focusedOrActiveItem[0].offsetTop;
|
const itemTop = focusedOrActiveItemLocal[0]?.offsetTop;
|
||||||
const itemHeight = focusedOrActiveItem[0].offsetHeight;
|
const itemHeight = focusedOrActiveItemLocal[0]?.offsetHeight;
|
||||||
const scrollPosition = itemTop - dropdownHeight / 2 + itemHeight / 2;
|
const scrollPosition = itemTop - dropdownHeight / 2 + itemHeight / 2;
|
||||||
dropdown.scrollTo({
|
dropdown.scrollTo({
|
||||||
top: scrollPosition,
|
top: scrollPosition,
|
||||||
|
|||||||
Reference in New Issue
Block a user