@teamnovu/kit-vue-forms 0.2.12 → 0.2.13
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/composables/useForm.d.ts +1 -2
- package/dist/composables/useValidation.d.ts +12 -1
- package/dist/index.js +303 -280
- package/dist/types/validation.d.ts +1 -1
- package/dist/utils/submitHandler.d.ts +3 -7
- package/package.json +1 -1
- package/src/composables/useForm.ts +21 -13
- package/src/composables/useValidation.ts +44 -6
- package/src/types/validation.ts +1 -1
- package/src/utils/submitHandler.ts +14 -22
- package/tests/useValidation.test.ts +59 -9
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { Form, FormDataDefault } from '../types/form';
|
|
4
|
-
import { ValidationStrategy } from '../types/validation';
|
|
5
4
|
import { ValidationOptions } from './useValidation';
|
|
5
|
+
export declare const defaults: Omit<UseFormOptions<FormDataDefault>, 'initialData' | 'errors' | 'schema' | 'validateFn'>;
|
|
6
6
|
export interface UseFormOptions<T extends FormDataDefault, TOut = T> extends ValidationOptions<T, TOut> {
|
|
7
7
|
initialData: MaybeRefOrGetter<T>;
|
|
8
|
-
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
9
8
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
10
9
|
}
|
|
11
10
|
export declare function useForm<T extends FormDataDefault, TOut = T>(options: UseFormOptions<T, TOut> & {
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { MaybeRef, Ref, ComputedRef } from 'vue';
|
|
1
|
+
import { MaybeRef, MaybeRefOrGetter, Ref, ComputedRef } from 'vue';
|
|
2
2
|
import { default as z } from 'zod';
|
|
3
3
|
import { FormDataDefault } from '../types/form';
|
|
4
4
|
import { ErrorBag, ValidationFunction, ValidationResult, Validator } from '../types/validation';
|
|
5
5
|
import { ValidationErrors } from '..';
|
|
6
|
+
export declare const defaults: ValidationOptions<FormDataDefault>;
|
|
7
|
+
export interface ValidationFlags {
|
|
8
|
+
validateOnBlur?: MaybeRefOrGetter<boolean>;
|
|
9
|
+
validateOnFormOpen?: MaybeRefOrGetter<boolean>;
|
|
10
|
+
validateOnSubmit?: MaybeRefOrGetter<boolean>;
|
|
11
|
+
validateOnDataChange?: MaybeRefOrGetter<boolean>;
|
|
12
|
+
}
|
|
6
13
|
export interface ValidatorOptions<T, TOut = T> {
|
|
7
14
|
schema?: MaybeRef<z.ZodType<TOut, unknown> | undefined>;
|
|
8
15
|
validateFn?: MaybeRef<ValidationFunction<T, TOut> | undefined>;
|
|
9
16
|
}
|
|
10
17
|
export interface ValidationOptions<T, TOut = T> extends ValidatorOptions<T, TOut> {
|
|
11
18
|
errors?: MaybeRef<ErrorBag | undefined>;
|
|
19
|
+
validationBeforeSubmit?: ValidationFlags;
|
|
20
|
+
validationAfterSubmit?: ValidationFlags;
|
|
12
21
|
}
|
|
13
22
|
export declare const SuccessValidationResult: ValidationResult<never>;
|
|
14
23
|
export declare function createValidator<T extends FormDataDefault, TOut = T>(options: ValidatorOptions<T, TOut>): Ref<Validator<T, TOut> | undefined>;
|
|
@@ -17,6 +26,8 @@ export declare function useValidation<T extends FormDataDefault, TOut = T>(formS
|
|
|
17
26
|
}, options: ValidationOptions<T, TOut>): {
|
|
18
27
|
validateForm: () => Promise<ValidationResult<TOut>>;
|
|
19
28
|
validateField: (path: string) => Promise<ValidationResult<TOut>>;
|
|
29
|
+
validateStrategy: <K extends keyof ValidationFlags>(flag: K, path: string) => Promise<ValidationResult<TOut>> | undefined;
|
|
30
|
+
canValidate: <K extends keyof ValidationFlags>(flag: K) => boolean;
|
|
20
31
|
defineValidator: <TData extends T, TDataOut extends TOut>(options: ValidatorOptions<TData, TDataOut> | Ref<Validator<TData, TDataOut>>) => Ref<Validator<TData, TDataOut> | undefined, Validator<TData, TDataOut> | undefined>;
|
|
21
32
|
isValid: ComputedRef<boolean>;
|
|
22
33
|
reset: () => void;
|