@teamnovu/kit-vue-forms 0.1.3 → 0.1.5
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/index.js +15 -12
- package/dist/utils/rc.d.ts +3 -0
- package/package.json +1 -1
- package/src/composables/useValidation.ts +10 -6
- package/src/utils/rc.ts +3 -0
package/dist/index.js
CHANGED
|
@@ -284,16 +284,21 @@ function he(r, e) {
|
|
|
284
284
|
validators: W([b(e)]),
|
|
285
285
|
isValidated: !1,
|
|
286
286
|
errors: f(e.errors) ?? m.errors
|
|
287
|
-
})
|
|
287
|
+
}), s = (l = m.errors) => {
|
|
288
|
+
t.errors = S(f(e.errors) ?? m.errors, l);
|
|
289
|
+
};
|
|
288
290
|
F(() => f(e.errors), async () => {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
+
if (t.isValidated) {
|
|
292
|
+
const l = await n();
|
|
293
|
+
s(l.errors);
|
|
294
|
+
} else
|
|
295
|
+
s();
|
|
291
296
|
}, { immediate: !0 }), F(
|
|
292
297
|
[() => t.validators],
|
|
293
298
|
async (l) => {
|
|
294
299
|
if (t.isValidated)
|
|
295
300
|
if (l) {
|
|
296
|
-
const c = await
|
|
301
|
+
const c = await n();
|
|
297
302
|
t.errors = c.errors;
|
|
298
303
|
} else
|
|
299
304
|
t.errors = m.errors;
|
|
@@ -302,7 +307,7 @@ function he(r, e) {
|
|
|
302
307
|
), F(() => r.data, () => {
|
|
303
308
|
t.isValidated && h();
|
|
304
309
|
});
|
|
305
|
-
const
|
|
310
|
+
const o = (l) => {
|
|
306
311
|
const c = k(l) ? l : b(l);
|
|
307
312
|
return t.validators.push(c), Q() && X(() => {
|
|
308
313
|
t.validators = t.validators.filter(
|
|
@@ -310,7 +315,7 @@ function he(r, e) {
|
|
|
310
315
|
);
|
|
311
316
|
}), c;
|
|
312
317
|
};
|
|
313
|
-
async function
|
|
318
|
+
async function n() {
|
|
314
319
|
const l = await Promise.all(
|
|
315
320
|
t.validators.filter((u) => f(u) !== void 0).map((u) => f(u).validate(r.data))
|
|
316
321
|
), c = l.every((u) => u.isValid);
|
|
@@ -324,11 +329,9 @@ function he(r, e) {
|
|
|
324
329
|
isValid: c
|
|
325
330
|
};
|
|
326
331
|
}
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const l = await o();
|
|
331
|
-
return n(l.errors), t.isValidated = !0, {
|
|
332
|
+
const h = async () => {
|
|
333
|
+
const l = await n();
|
|
334
|
+
return s(l.errors), t.isValidated = !0, {
|
|
332
335
|
isValid: !M(l.errors),
|
|
333
336
|
errors: t.errors
|
|
334
337
|
};
|
|
@@ -336,7 +339,7 @@ function he(r, e) {
|
|
|
336
339
|
return {
|
|
337
340
|
...N(t),
|
|
338
341
|
validateForm: h,
|
|
339
|
-
defineValidator:
|
|
342
|
+
defineValidator: o,
|
|
340
343
|
isValid: v
|
|
341
344
|
};
|
|
342
345
|
}
|
package/dist/utils/rc.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -122,11 +122,19 @@ export function useValidation<T extends FormDataDefault>(
|
|
|
122
122
|
errors: unref(options.errors) ?? SuccessValidationResult.errors,
|
|
123
123
|
})
|
|
124
124
|
|
|
125
|
+
const updateErrors = (newErrors: ErrorBag = SuccessValidationResult.errors) => {
|
|
126
|
+
validationState.errors = mergeErrors(unref(options.errors) ?? SuccessValidationResult.errors, newErrors)
|
|
127
|
+
}
|
|
128
|
+
|
|
125
129
|
// Watch for changes in the error bag and update validation state
|
|
126
130
|
watch(() => unref(options.errors), async () => {
|
|
127
|
-
|
|
131
|
+
if (validationState.isValidated) {
|
|
132
|
+
const validationResults = await getValidationResults()
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
updateErrors(validationResults.errors)
|
|
135
|
+
} else {
|
|
136
|
+
updateErrors()
|
|
137
|
+
}
|
|
130
138
|
}, { immediate: true })
|
|
131
139
|
|
|
132
140
|
// Watch for changes in validation function or schema
|
|
@@ -194,10 +202,6 @@ export function useValidation<T extends FormDataDefault>(
|
|
|
194
202
|
}
|
|
195
203
|
}
|
|
196
204
|
|
|
197
|
-
const updateErrors = (newErrors: ErrorBag) => {
|
|
198
|
-
validationState.errors = mergeErrors(unref(options.errors) ?? SuccessValidationResult.errors, newErrors)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
205
|
const validateForm = async (): Promise<ValidationResult> => {
|
|
202
206
|
const validationResults = await getValidationResults()
|
|
203
207
|
|