edvoyui-component-library-test-flight 0.0.237 → 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.
@@ -31,7 +31,7 @@
31
31
  </EUIButton>
32
32
  </div>
33
33
  <template v-if="errors && Object.keys(errors).length">
34
- <EUIErrorMessage :errors="errors" :name="name" />
34
+ <EUIErrorMessage :errors="errors" :name="name" class="mt-2" />
35
35
  </template>
36
36
  </div>
37
37
  </template>
@@ -48,12 +48,12 @@
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
 
55
55
  <div class="errors" v-if="errorMessage">
56
- <p class="mt-2 text-xs text-red-500">
56
+ <p class="text-xs text-red-500">
57
57
  {{ errorMessage }}
58
58
  </p>
59
59
  </div>
@@ -161,10 +161,15 @@ const inputValue = computed(() => {
161
161
  });
162
162
 
163
163
  const mobile = ref(props.modelValue);
164
+ const isTouched = ref(false);
165
+ const telephoneIsValid = ref(props.isValid);
164
166
  const listener = computed(() => props.modelValue);
165
167
  watch(listener, (value) => {
166
168
  mobile.value = value;
167
169
  });
170
+ watch(isValid, (value) => {
171
+ telephoneIsValid.value = value;
172
+ });
168
173
 
169
174
  // Make bindProps a reactive computed property
170
175
  const bindProps = computed(() => ({
@@ -199,10 +204,16 @@ const bindProps = computed(() => ({
199
204
  }));
200
205
 
201
206
  const onInputChanged = (_formattedNumber: string, phoneObject: any) => {
202
- hasError.value = phoneObject.valid ? true : false;
207
+ telephoneIsValid.value = Boolean(phoneObject.valid);
208
+ hasError.value = telephoneIsValid.value;
203
209
  emit("update:modelValue", phoneObject.number);
204
210
  };
205
211
 
212
+ const onBlur = () => {
213
+ isTouched.value = true;
214
+ emit("blur");
215
+ };
216
+
206
217
  const firstTime = ref(true);
207
218
  const onCountryChanged = (_event: VueTelInputCountryOption) => {
208
219
  if (!firstTime.value) {
@@ -216,7 +227,7 @@ onUpdated(() => {
216
227
  }, 1500);
217
228
  });
218
229
 
219
- const errorMessage = computed(() => {
230
+ const externalErrorMessage = computed(() => {
220
231
  if (Array.isArray(props.errors)) {
221
232
  if (typeof props.errors?.at(0) === "object") {
222
233
  return props.errors?.at(0)?.$message;
@@ -232,6 +243,19 @@ const errorMessage = computed(() => {
232
243
  }
233
244
  });
234
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
+
235
259
  const getIconClass = () => {
236
260
  switch (props.iconType) {
237
261
  case "startIcon":
@@ -288,4 +312,4 @@ const focusInput = () => {
288
312
  @apply rounded-md py-2;
289
313
  }
290
314
  }
291
- </style>
315
+ </style>