edvoyui-component-library-test-flight 0.0.238 → 0.0.239

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.
@@ -48,7 +48,7 @@
48
48
  :class="[getIconClass()]"
49
49
  @on-input="onInputChanged"
50
50
  @country-changed="onCountryChanged"
51
- @blur="$emit('blur')"
51
+ @blur="onBlur"
52
52
  ></vue-tel-input>
53
53
  </button>
54
54
 
@@ -75,7 +75,6 @@
75
75
  import { computed, onUpdated, PropType, ref, toRefs, watch } from "vue";
76
76
  import { VueTelInput, VueTelInputCountryOption } from "vue-tel-input";
77
77
  import "vue-tel-input/vue-tel-input.css";
78
- import EUIErrorMessage from "../errorMessage/EUIErrorMessage.vue";
79
78
 
80
79
  const emit = defineEmits(["update:modelValue", "blur", "update:isValid"]);
81
80
 
@@ -162,10 +161,15 @@ const inputValue = computed(() => {
162
161
  });
163
162
 
164
163
  const mobile = ref(props.modelValue);
164
+ const isTouched = ref(false);
165
+ const telephoneIsValid = ref(props.isValid);
165
166
  const listener = computed(() => props.modelValue);
166
167
  watch(listener, (value) => {
167
168
  mobile.value = value;
168
169
  });
170
+ watch(isValid, (value) => {
171
+ telephoneIsValid.value = value;
172
+ });
169
173
 
170
174
  // Make bindProps a reactive computed property
171
175
  const bindProps = computed(() => ({
@@ -200,10 +204,16 @@ const bindProps = computed(() => ({
200
204
  }));
201
205
 
202
206
  const onInputChanged = (_formattedNumber: string, phoneObject: any) => {
203
- hasError.value = phoneObject.valid ? true : false;
207
+ telephoneIsValid.value = Boolean(phoneObject.valid);
208
+ hasError.value = telephoneIsValid.value;
204
209
  emit("update:modelValue", phoneObject.number);
205
210
  };
206
211
 
212
+ const onBlur = () => {
213
+ isTouched.value = true;
214
+ emit("blur");
215
+ };
216
+
207
217
  const firstTime = ref(true);
208
218
  const onCountryChanged = (_event: VueTelInputCountryOption) => {
209
219
  if (!firstTime.value) {
@@ -217,7 +227,7 @@ onUpdated(() => {
217
227
  }, 1500);
218
228
  });
219
229
 
220
- const errorMessage = computed(() => {
230
+ const externalErrorMessage = computed(() => {
221
231
  if (Array.isArray(props.errors)) {
222
232
  if (typeof props.errors?.at(0) === "object") {
223
233
  return props.errors?.at(0)?.$message;
@@ -233,6 +243,19 @@ const errorMessage = computed(() => {
233
243
  }
234
244
  });
235
245
 
246
+ const internalErrorMessage = computed(() => {
247
+ if (!isTouched.value || props.readonly || props.disabled) return "";
248
+
249
+ const value = String(mobile.value ?? "").trim();
250
+ if (!value) return props.required ? "Mobile number is required" : "";
251
+
252
+ return telephoneIsValid.value ? "" : "Enter a valid phone number";
253
+ });
254
+
255
+ const errorMessage = computed(
256
+ () => externalErrorMessage.value || internalErrorMessage.value,
257
+ );
258
+
236
259
  const getIconClass = () => {
237
260
  switch (props.iconType) {
238
261
  case "startIcon":
@@ -289,4 +312,4 @@ const focusInput = () => {
289
312
  @apply rounded-md py-2;
290
313
  }
291
314
  }
292
- </style>
315
+ </style>