@winchsa/ui 0.1.14 → 0.1.16

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.
@@ -7,7 +7,10 @@ const props = defineProps({
7
7
  hideDetails: { type: Boolean, required: false },
8
8
  label: { type: String, required: false },
9
9
  customId: { type: String, required: false },
10
- errorMessages: { type: [Array, String], required: false }
10
+ errorMessages: { type: [Array, String], required: false },
11
+ validateOn: { type: null, required: false, default: "submit lazy" },
12
+ error: { type: Boolean, required: false },
13
+ rules: { type: Array, required: false }
11
14
  });
12
15
  const model = defineModel({ type: [Array, null], ...{ default: ["", "", "", ""] } });
13
16
  const LangLabel = computed(() => props.label ? t(props.label) : "");
@@ -63,12 +66,6 @@ const handleInput = (e, index) => {
63
66
  const clear = () => {
64
67
  model.value = null;
65
68
  };
66
- const requiredRule = (value) => {
67
- if (value.length !== 4 || !value.every((item) => item !== "")) {
68
- return t("validation.required");
69
- }
70
- return true;
71
- };
72
69
  watch(() => model.value, (newVal) => {
73
70
  if (Array.isArray(newVal)) {
74
71
  model.value = newVal;
@@ -83,8 +80,9 @@ watch(() => model.value, (newVal) => {
83
80
  <VValidation
84
81
  v-slot="{ errorMessages: validationErrors, isValid }"
85
82
  v-model="model"
86
- :rules="[requiredRule]"
87
- validate-on="input lazy"
83
+ :error="error"
84
+ :rules="rules"
85
+ :validate-on="validateOn"
88
86
  >
89
87
  <div class="d-flex flex-column h-100">
90
88
  <VLabel
@@ -96,7 +94,7 @@ watch(() => model.value, (newVal) => {
96
94
  class="app-license-plate-input position-relative"
97
95
  style="min-height: 45px;"
98
96
  :class="{
99
- 'app-license-plate-input--error': !isValid.value && validationErrors.value?.length > 0
97
+ 'app-license-plate-input--error': error || isValid.value === false
100
98
  }"
101
99
  >
102
100
  <input
@@ -1,8 +1,12 @@
1
+ import type { ValidateOn } from '../../types';
1
2
  type __VLS_Props = {
2
3
  hideDetails?: boolean;
3
4
  label?: string;
4
5
  customId?: string;
5
6
  errorMessages?: string[] | string;
7
+ validateOn?: ValidateOn;
8
+ error?: boolean;
9
+ rules?: ((value: unknown) => string)[];
6
10
  };
7
11
  type __VLS_PublicProps = {
8
12
  modelValue?: string[] | null;
@@ -11,5 +15,7 @@ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {}, {},
11
15
  "update:modelValue": (value: string[] | null) => any;
12
16
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
13
17
  "onUpdate:modelValue"?: ((value: string[] | null) => any) | undefined;
14
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
+ }>, {
19
+ validateOn: "submit" | "lazy" | "input" | "blur" | "input lazy" | "blur lazy" | "submit lazy" | "lazy input" | "lazy blur" | "lazy submit";
20
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
21
  export default _default;
@@ -12,6 +12,8 @@ const props = defineProps({
12
12
  errorMessages: { type: [Array, String], required: false },
13
13
  type: { type: null, required: false },
14
14
  disabled: { type: Boolean, required: false },
15
+ validateOn: { type: null, required: false, default: "submit lazy" },
16
+ error: { type: Boolean, required: false },
15
17
  rules: { type: Array, required: false }
16
18
  });
17
19
  const emit = defineEmits(["update:model-value"]);
@@ -142,8 +144,8 @@ watch(() => props.modelValue, (val) => {
142
144
  <VValidation
143
145
  v-slot="{ errorMessages: validationErrors, isValid }"
144
146
  v-model="date"
147
+ :error="error"
145
148
  :rules="rules"
146
- validate-on="input lazy"
147
149
  >
148
150
  <div class="d-flex flex-column">
149
151
  <VLabel
@@ -152,7 +154,7 @@ watch(() => props.modelValue, (val) => {
152
154
  :text="LangLabel"
153
155
  />
154
156
  <div class="app-date-input position-relative" style="min-height: 45px;" :class="{
155
- 'app-date-input--error': !isValid.value || yearIsInvalid,
157
+ 'app-date-input--error': isValid.value === false || yearIsInvalid || error,
156
158
  'app-date-input--disabled': disabled
157
159
  }">
158
160
  <input
@@ -1,3 +1,4 @@
1
+ import type { ValidateOn } from '../../types';
1
2
  type __VLS_Props = {
2
3
  hideDetails?: boolean;
3
4
  label?: string;
@@ -6,6 +7,8 @@ type __VLS_Props = {
6
7
  errorMessages?: string[] | string;
7
8
  type?: 'gregorian' | 'hijri' | string | undefined;
8
9
  disabled?: boolean;
10
+ validateOn?: ValidateOn;
11
+ error?: boolean;
9
12
  rules?: ((value: unknown) => string)[];
10
13
  };
11
14
  declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
@@ -13,6 +16,7 @@ declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {
13
16
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
14
17
  "onUpdate:model-value"?: ((value: string) => any) | undefined;
15
18
  }>, {
19
+ validateOn: "submit" | "lazy" | "input" | "blur" | "input lazy" | "blur lazy" | "submit lazy" | "lazy input" | "lazy blur" | "lazy submit";
16
20
  customId: string;
17
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
22
  export default _default;
@@ -48,6 +48,7 @@ declare const headers: import("vue").ComputedRef<{
48
48
  options?: Record<string, unknown>[] | import("../../types").OptionItem[] | import("vue").Ref<import("../../types").OptionItem[]>;
49
49
  disableIfEmpty?: boolean;
50
50
  maxDate?: Date | null;
51
+ validateOn?: import("../../types").ValidateOn;
51
52
  }[]>;
52
53
  declare const moduleIdentifier: import("vue").ComputedRef<string>;
53
54
  declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
@@ -175,7 +175,7 @@ const placeholder = (header) => {
175
175
  :params="autoCompleteParams"
176
176
  :search-internally="header.searchInternally"
177
177
  :searchable="header.searchable"
178
- :fetch-enabled="header.dependsOn ? item[`${header.dependsOn}`] : true"
178
+ :fetch-enabled="header.dependsOn ? Boolean(item[`${header.dependsOn}`]) : true"
179
179
  :group-label="header.groupLabel || 'name'"
180
180
  :group-values="header.groupValues || 'children'"
181
181
  :item-label="header.itemLabel || 'name'"
@@ -194,6 +194,7 @@ const placeholder = (header) => {
194
194
  <DatePicker
195
195
  v-if="header.type === 'datepicker'"
196
196
  v-model="item[header.key]"
197
+ :validate-on="header.validateOn"
197
198
  class="pa-0 h-100 app-input-outline"
198
199
  :placeholder="placeholder(header)"
199
200
  :rules="header.rules"
@@ -212,6 +213,7 @@ const placeholder = (header) => {
212
213
  <TimePicker
213
214
  v-if="header.type === 'timepicker'"
214
215
  v-model="item[header.key]"
216
+ :validate-on="header.validateOn"
215
217
  class="pa-0 h-100 app-flex-1 app-max-w-150px app-input-outline"
216
218
  :rules="header.rules"
217
219
  :show-icon="false"
@@ -225,6 +227,9 @@ const placeholder = (header) => {
225
227
  <LicensePlateInput
226
228
  v-if="header.type === 'license_plate'"
227
229
  v-model="item[header.key]"
230
+ :validate-on="header.validateOn"
231
+ :rules="header.rules"
232
+ :error="error"
228
233
  class="pa-0 h-100 app-flex-1 app-max-w-150px app-input-outline"
229
234
  :custom-id="`field.${index}.${header.key}`"
230
235
  :error-messages="errorMessages"
@@ -235,12 +240,13 @@ const placeholder = (header) => {
235
240
  v-if="header.type === 'manual_date'"
236
241
  v-model="item[header.key]"
237
242
  class="pa-0 h-100 app-flex-1 app-input-outline"
238
- :custom-id="`field.${index}.${header.key}`"
243
+ :validate-on="header.validateOn"
239
244
  :rules="header.rules"
245
+ :error="error"
246
+ :custom-id="`field.${index}.${header.key}`"
240
247
  :type="item[header.dependsOn]"
241
248
  :disabled="isDisabled"
242
249
  :error-messages="errorMessages"
243
- :error="error"
244
250
  hide-details
245
251
  />
246
252
  </template>
package/dist/types.d.ts CHANGED
@@ -8,6 +8,9 @@ string |
8
8
  number |
9
9
  null
10
10
 
11
+ export type ValidateOn = "submit lazy" | "lazy" | "blur" | "input" | "submit" | "input lazy" | "blur lazy" | "lazy input" | "lazy blur" | "lazy submit" | undefined
12
+
13
+
11
14
  export type ItemData = Record<string, string | number | null>
12
15
  export type Params = Record<string, string | number | null | undefined | string[] | Date[] | number[] | (string | number)[] | boolean>
13
16
 
@@ -144,6 +147,7 @@ export type EditableDataTableItem = {
144
147
  options?: Record<string, unknown>[] | OptionItem[] | Ref<OptionItem[]>
145
148
  disableIfEmpty?: boolean
146
149
  maxDate?: Date | null
150
+ validateOn?: ValidateOn
147
151
  }
148
152
 
149
153
  export type OptionItem = {
@@ -32,6 +32,7 @@ export declare const ruleValidator: () => {
32
32
  month?: string;
33
33
  day?: string;
34
34
  }) => string | true;
35
+ requiredPlateValidator: (value: string[] | null | undefined) => string | true;
35
36
  };
36
37
  export declare const useFormValidation: () => {
37
38
  validateAndScroll: (refVForm: VForm | undefined) => Promise<boolean>;
@@ -134,6 +134,12 @@ const ruleValidator = () => {
134
134
  }
135
135
  return true;
136
136
  };
137
+ const requiredPlateValidator = value => {
138
+ if (!value || !value?.every(val => val !== "")) {
139
+ return t("validation.required");
140
+ }
141
+ return true;
142
+ };
137
143
  const dateValidator = value => {
138
144
  if ((0, _utils.isEmpty)(value)) {
139
145
  return true;
@@ -168,7 +174,8 @@ const ruleValidator = () => {
168
174
  dateValidator,
169
175
  regexValidator,
170
176
  idNumberValidator,
171
- requiredManualDateValidator
177
+ requiredManualDateValidator,
178
+ requiredPlateValidator
172
179
  };
173
180
  };
174
181
  exports.ruleValidator = ruleValidator;
@@ -123,6 +123,12 @@ export const ruleValidator = () => {
123
123
  }
124
124
  return true;
125
125
  };
126
+ const requiredPlateValidator = (value) => {
127
+ if (!value || !value?.every((val) => val !== "")) {
128
+ return t("validation.required");
129
+ }
130
+ return true;
131
+ };
126
132
  const dateValidator = (value) => {
127
133
  if (isEmpty(value)) {
128
134
  return true;
@@ -155,7 +161,8 @@ export const ruleValidator = () => {
155
161
  dateValidator,
156
162
  regexValidator,
157
163
  idNumberValidator,
158
- requiredManualDateValidator
164
+ requiredManualDateValidator,
165
+ requiredPlateValidator
159
166
  };
160
167
  };
161
168
  export const useFormValidation = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winchsa/ui",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {