edvoyui-component-library-test-flight 0.0.240 → 0.0.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/telephone/EUITelephone.vue +32 -6
- package/dist/edvoy-ui.cjs.js +15 -15
- package/dist/edvoy-ui.es.js +3529 -3525
- package/dist/edvoy-ui.umd.js +27 -27
- package/package.json +1 -1
|
@@ -173,7 +173,19 @@ const mobile = ref(String(props.modelValue ?? ""));
|
|
|
173
173
|
const isTouched = ref(false);
|
|
174
174
|
const telephoneIsValid = ref(props.isValid);
|
|
175
175
|
const activeCountry = ref<CountryObject | null>(null);
|
|
176
|
+
const firstTime = ref(true);
|
|
176
177
|
const dynamicMaxLength = ref<number>(props.length);
|
|
178
|
+
const normalizeValueForCountry = (
|
|
179
|
+
value: string | number | null | undefined,
|
|
180
|
+
country: CountryObject | null,
|
|
181
|
+
) => {
|
|
182
|
+
const stringValue = String(value ?? "").trim();
|
|
183
|
+
if (!stringValue || stringValue.startsWith("+") || !country?.dialCode) {
|
|
184
|
+
return stringValue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return `+${country.dialCode}${stringValue.replace(/\D/g, "")}`;
|
|
188
|
+
};
|
|
177
189
|
const getCountryMaxLength = (
|
|
178
190
|
country: CountryObject | PhoneMeta["country"] | null,
|
|
179
191
|
) => {
|
|
@@ -183,14 +195,13 @@ const getCountryMaxLength = (
|
|
|
183
195
|
const example = getExampleNumber(countryCode, mobileExamples);
|
|
184
196
|
if (!example) return props.length;
|
|
185
197
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
);
|
|
198
|
+
const dialCodeLength = String(example.countryCallingCode ?? "").length;
|
|
199
|
+
|
|
200
|
+
return example.nationalNumber.length + dialCodeLength + 1;
|
|
190
201
|
};
|
|
191
202
|
const listener = computed(() => props.modelValue);
|
|
192
203
|
watch(listener, (value) => {
|
|
193
|
-
mobile.value =
|
|
204
|
+
mobile.value = normalizeValueForCountry(value, activeCountry.value);
|
|
194
205
|
});
|
|
195
206
|
watch(isValid, (value) => {
|
|
196
207
|
telephoneIsValid.value = value;
|
|
@@ -240,6 +251,19 @@ const onInputChanged = (
|
|
|
240
251
|
_formattedNumber: string,
|
|
241
252
|
phoneObject: TelephoneInputMeta,
|
|
242
253
|
) => {
|
|
254
|
+
const countryCode = phoneObject.country ?? activeCountry.value?.iso2;
|
|
255
|
+
const example = countryCode
|
|
256
|
+
? getExampleNumber(countryCode, mobileExamples)
|
|
257
|
+
: undefined;
|
|
258
|
+
const dialCode =
|
|
259
|
+
example?.countryCallingCode ?? activeCountry.value?.dialCode ?? "";
|
|
260
|
+
const phoneDigits = String(phoneObject.number ?? "").replace(/\D/g, "");
|
|
261
|
+
const nationalDigits = phoneDigits.slice(String(dialCode).length);
|
|
262
|
+
|
|
263
|
+
if (nationalDigits.length > 0) {
|
|
264
|
+
isTouched.value = true;
|
|
265
|
+
}
|
|
266
|
+
|
|
243
267
|
telephoneIsValid.value = Boolean(phoneObject.valid);
|
|
244
268
|
hasError.value = telephoneIsValid.value;
|
|
245
269
|
|
|
@@ -255,10 +279,12 @@ const onBlur = () => {
|
|
|
255
279
|
emit("blur");
|
|
256
280
|
};
|
|
257
281
|
|
|
258
|
-
const firstTime = ref(true);
|
|
259
282
|
const onCountryChanged = (country: CountryObject) => {
|
|
260
283
|
activeCountry.value = country;
|
|
261
284
|
dynamicMaxLength.value = getCountryMaxLength(country);
|
|
285
|
+
if (firstTime.value && props.modelValue) {
|
|
286
|
+
mobile.value = normalizeValueForCountry(props.modelValue, country);
|
|
287
|
+
}
|
|
262
288
|
if (!firstTime.value) {
|
|
263
289
|
emit("update:modelValue", "");
|
|
264
290
|
}
|