@teamnovu/kit-vue-forms 0.2.1 → 0.2.2
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.
|
@@ -9,10 +9,10 @@ export interface UseFormOptions<T extends FormDataDefault, TOut = T> extends Val
|
|
|
9
9
|
validationStrategy?: MaybeRef<ValidationStrategy>;
|
|
10
10
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
11
11
|
}
|
|
12
|
-
export declare function useForm<TSchema extends z.ZodType<FormDataDefault, FormDataDefault
|
|
12
|
+
export declare function useForm<TSchema extends z.ZodType<FormDataDefault, FormDataDefault>, InitialData extends DeepPartial<z.input<TSchema>>>(options: Omit<UseFormOptions<z.input<TSchema>, z.output<TSchema>>, 'initialData'> & {
|
|
13
13
|
schema: MaybeRef<TSchema>;
|
|
14
|
-
initialData:
|
|
15
|
-
}): Form<z.input<TSchema
|
|
14
|
+
initialData: MaybeRef<InitialData>;
|
|
15
|
+
}): Form<z.input<TSchema> & InitialData, z.output<TSchema> & InitialData>;
|
|
16
16
|
export declare function useForm<T extends FormDataDefault>(options: Omit<UseFormOptions<T, T>, 'schema'> & {
|
|
17
17
|
schema?: undefined;
|
|
18
18
|
}): Form<T, T>;
|
package/package.json
CHANGED
|
@@ -31,12 +31,15 @@ export interface UseFormOptions<T extends FormDataDefault, TOut = T>
|
|
|
31
31
|
/* eslint-disable no-redeclare */
|
|
32
32
|
// Overload: with schema - infer types from schema
|
|
33
33
|
// initialData can be partial, but provided fields must match schema types
|
|
34
|
-
export function useForm<
|
|
34
|
+
export function useForm<
|
|
35
|
+
TSchema extends z.ZodType<FormDataDefault, FormDataDefault>,
|
|
36
|
+
InitialData extends DeepPartial<z.input<TSchema>>,
|
|
37
|
+
>(
|
|
35
38
|
options: Omit<UseFormOptions<z.input<TSchema>, z.output<TSchema>>, 'initialData'> & {
|
|
36
39
|
schema: MaybeRef<TSchema>
|
|
37
|
-
initialData:
|
|
40
|
+
initialData: MaybeRef<InitialData>
|
|
38
41
|
},
|
|
39
|
-
): Form<z.input<TSchema
|
|
42
|
+
): Form<z.input<TSchema> & InitialData, z.output<TSchema> & InitialData>
|
|
40
43
|
|
|
41
44
|
// Overload: without schema - infer types from initialData
|
|
42
45
|
export function useForm<T extends FormDataDefault>(
|
package/tests/nestedPath.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { nextTick } from 'vue'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import { useForm } from '../src/composables/useForm'
|
|
5
5
|
import { isValidResult } from '../src/utils/validation'
|
|
6
|
+
import { FormField } from '../src'
|
|
6
7
|
|
|
7
8
|
describe('Nested Path Handling', () => {
|
|
8
9
|
interface TestFormData {
|
|
@@ -556,7 +557,7 @@ describe('Nested Path Handling', () => {
|
|
|
556
557
|
it('should handle large numbers of nested fields', () => {
|
|
557
558
|
const form = useForm({ initialData })
|
|
558
559
|
|
|
559
|
-
const fields = []
|
|
560
|
+
const fields: FormField<string, string>[] = []
|
|
560
561
|
|
|
561
562
|
// Create many nested fields
|
|
562
563
|
for (let i = 0; i < 100; i++) {
|
package/tests/useField.test.ts
CHANGED
package/tests/useForm.test.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { z } from 'zod'
|
|
|
4
4
|
import { useForm } from '../src/composables/useForm'
|
|
5
5
|
import { isValidResult } from '../src/utils/validation'
|
|
6
6
|
|
|
7
|
-
const scope = effectScope()
|
|
8
|
-
|
|
9
7
|
describe('useForm', () => {
|
|
10
8
|
it('should initialize form with initial data', () => {
|
|
11
9
|
const initialData = {
|
|
@@ -481,7 +479,7 @@ describe('useForm', () => {
|
|
|
481
479
|
{ timeout: 500 },
|
|
482
480
|
async () => {
|
|
483
481
|
const initialData = ref({
|
|
484
|
-
name:
|
|
482
|
+
name: undefined as undefined | number,
|
|
485
483
|
})
|
|
486
484
|
|
|
487
485
|
const schema = z.object({
|
|
@@ -307,10 +307,14 @@ describe('useValidation', () => {
|
|
|
307
307
|
it('should not validate other fields than the blurred one', async () => {
|
|
308
308
|
const schema = z.object({
|
|
309
309
|
name: z.string().min(2),
|
|
310
|
-
email: z.
|
|
310
|
+
email: z.email(),
|
|
311
311
|
})
|
|
312
312
|
|
|
313
|
-
const initialData = {
|
|
313
|
+
const initialData = {
|
|
314
|
+
name: 'A',
|
|
315
|
+
email: 'invalid-email',
|
|
316
|
+
}
|
|
317
|
+
|
|
314
318
|
const form = useForm({
|
|
315
319
|
initialData,
|
|
316
320
|
schema,
|