vue3-form-validation
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -22,6 +22,6 @@ import { Ref, ComputedRef, UnwrapRef } from 'vue'; | ||
export declare type TransformedFormData<T extends object> = T extends any ? { | ||
[K in keyof T]: T[K] extends Field<infer TValue> | undefined ? T[K] & Field<any> extends Field<any> ? TransformedField<UnwrapRef<TValue>> : TransformedField<UnwrapRef<TValue>> : T[K] extends Record<string, unknown> | any[] ? TransformedFormData<T[K]> : T[K]; | ||
[K in keyof T]: T[K] extends Field<infer TValue> | undefined ? T[K] extends undefined ? undefined : TransformedField<UnwrapRef<TValue>> : T[K] extends Record<string, unknown> | any[] ? TransformedFormData<T[K]> : T[K]; | ||
} : never; | ||
export declare type FormData<T extends object> = T extends any ? { | ||
[K in keyof T]: T[K] extends Field<infer TValue> | undefined ? T[K] & Field<any> extends Field<any> ? UnwrapRef<TValue> : UnwrapRef<TValue> : T[K] extends Record<string, unknown> | any[] ? FormData<T[K]> : T[K]; | ||
[K in keyof T]: T[K] extends Field<infer TValue> | undefined ? UnwrapRef<TValue> : T[K] extends object ? FormData<T[K]> : T[K]; | ||
} : never; | ||
@@ -37,3 +37,3 @@ export declare type Keys = readonly (string | number)[]; | ||
errors: ComputedRef<string[]>; | ||
validateFields(): Promise<FormData<T>>; | ||
validateFields(names?: string[]): Promise<FormData<T>>; | ||
resetFields(formData?: Partial<FormData<T>>): void; | ||
@@ -40,0 +40,0 @@ add<Ks extends Keys>(path: readonly [...Ks], value: DeepIndex<T, Ks> extends Array<infer TArray> ? TArray : DeepIndex<T, Ks>): void; |
@@ -34,6 +34,6 @@ import { reactive } from 'vue'; | ||
errors: form.getErrors(), | ||
async validateFields() { | ||
async validateFields(names = []) { | ||
form.submitting.value = true; | ||
const resultFormData = getResultFormData(transformedFormData); | ||
const hasError = await promiseCancel.race(form.validateAll()); | ||
const hasError = await promiseCancel.race(form.validateAll(names)); | ||
form.submitting.value = false; | ||
@@ -58,11 +58,14 @@ if (hasError) { | ||
add(path, value) { | ||
const box = { value }; | ||
transformFormData(form, box); | ||
const x = _path(path, transformedFormData); | ||
if (Array.isArray(x)) { | ||
x.push(box.value); | ||
const lastKey = path[path.length - 1]; | ||
if (typeof lastKey !== 'undefined') { | ||
const box = { [lastKey]: value }; | ||
transformFormData(form, box); | ||
const x = _path(path, transformedFormData); | ||
if (Array.isArray(x)) { | ||
x.push(box[lastKey]); | ||
} | ||
else { | ||
set(transformedFormData, path, box[lastKey]); | ||
} | ||
} | ||
else { | ||
set(transformedFormData, path, box.value); | ||
} | ||
}, | ||
@@ -69,0 +72,0 @@ remove(path) { |
@@ -14,7 +14,8 @@ import { Rule } from '../composition/useValidation'; | ||
validate(uid: number): Promise<PromiseSettledResult<ValidateResult>[]> | undefined; | ||
validateAll(): Promise<boolean>; | ||
validateAll(names: string[]): Promise<boolean>; | ||
onDelete(uid: number): void; | ||
getErrors(): import("vue").ComputedRef<string[]>; | ||
resetFields(toDefaultValues?: boolean): void; | ||
private getPromisesFor; | ||
private getPromisesForKeys; | ||
private getPromisesForNames; | ||
private isEveryFormFieldTouchedWith; | ||
@@ -21,0 +22,0 @@ private static validateFactory; |
@@ -63,14 +63,8 @@ import { computed, reactive, ref, unref } from 'vue'; | ||
...simple.vs.map(v => v([simple.formField.modelValue])), | ||
...this.getPromisesFor(simple.keys) | ||
...this.getPromisesForKeys(simple.keys) | ||
]); | ||
} | ||
} | ||
async validateAll() { | ||
const promises = []; | ||
for (const { formField, vs } of this.simpleMap.values()) { | ||
formField.touched = true; | ||
promises.push(...vs.map(v => v([formField.modelValue]))); | ||
} | ||
promises.push(...this.getPromisesFor(this.keyedSetMap.keys())); | ||
const settledResults = await Promise.allSettled(promises); | ||
async validateAll(names) { | ||
const settledResults = await Promise.allSettled(this.getPromisesForNames(names)); | ||
for (const result of settledResults) { | ||
@@ -106,3 +100,3 @@ if (result.status === 'rejected') { | ||
} | ||
getPromisesFor(keys) { | ||
getPromisesForKeys(keys) { | ||
const promises = []; | ||
@@ -123,2 +117,23 @@ for (const key of keys) { | ||
} | ||
getPromisesForNames(names) { | ||
const promises = []; | ||
if (names.length > 0) { | ||
const nameSet = new Set(names); | ||
for (const { formField, keys, vs } of this.simpleMap.values()) { | ||
if (nameSet.has(formField.name)) { | ||
formField.touched = true; | ||
promises.push(...vs.map(v => v([formField.modelValue]))); | ||
promises.push(...this.getPromisesForKeys(keys)); | ||
} | ||
} | ||
} | ||
else { | ||
for (const { formField, vs } of this.simpleMap.values()) { | ||
formField.touched = true; | ||
promises.push(...vs.map(v => v([formField.modelValue]))); | ||
} | ||
promises.push(...this.getPromisesForKeys(this.keyedSetMap.keys())); | ||
} | ||
return promises; | ||
} | ||
isEveryFormFieldTouchedWith(key) { | ||
@@ -125,0 +140,0 @@ let everyFormFieldIsTouched = true; |
{ | ||
"name": "vue3-form-validation", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "Vue composition function for Form Validation", | ||
@@ -60,3 +60,3 @@ "author": { | ||
"ts-node": "^10.0.0", | ||
"tsd": "^0.15.1", | ||
"tsd": "^0.16.0", | ||
"typescript": "^4.3.2", | ||
@@ -63,0 +63,0 @@ "vite": "^2.3.4", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43171
880
0