@tanstack/vue-form 0.3.2 → 0.3.4
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/build/legacy/createFormFactory.d.cts +1 -0
- package/build/legacy/createFormFactory.d.ts +1 -0
- package/build/legacy/index.d.cts +2 -1
- package/build/legacy/index.d.ts +2 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +6 -3
- package/build/legacy/types.d.ts +6 -3
- package/build/legacy/useField.cjs +5 -2
- package/build/legacy/useField.cjs.map +1 -1
- package/build/legacy/useField.d.cts +23 -17
- package/build/legacy/useField.d.ts +23 -17
- package/build/legacy/useField.js +8 -3
- package/build/legacy/useField.js.map +1 -1
- package/build/legacy/useForm.cjs.map +1 -1
- package/build/legacy/useForm.d.cts +2 -1
- package/build/legacy/useForm.d.ts +2 -1
- package/build/legacy/useForm.js.map +1 -1
- package/build/lib/createFormFactory.d.ts +8 -0
- package/build/lib/createFormFactory.js +12 -0
- package/build/lib/formContext.d.ts +11 -0
- package/build/lib/formContext.js +12 -0
- package/build/lib/index.d.ts +5 -0
- package/build/lib/index.js +5 -0
- package/build/lib/tests/useField.test.d.ts +2 -0
- package/build/lib/tests/useField.test.jsx +109 -0
- package/build/lib/tests/useForm.test.d.ts +2 -0
- package/build/lib/tests/useForm.test.jsx +71 -0
- package/build/lib/tests/utils.d.ts +1 -0
- package/build/lib/tests/utils.js +5 -0
- package/build/lib/types.d.ts +4 -0
- package/build/lib/types.js +1 -0
- package/build/lib/useField.d.ts +42 -0
- package/build/lib/useField.jsx +41 -0
- package/build/lib/useForm.d.ts +19 -0
- package/build/lib/useForm.jsx +35 -0
- package/build/modern/createFormFactory.d.cts +1 -0
- package/build/modern/createFormFactory.d.ts +1 -0
- package/build/modern/index.d.cts +2 -1
- package/build/modern/index.d.ts +2 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +6 -3
- package/build/modern/types.d.ts +6 -3
- package/build/modern/useField.cjs +5 -2
- package/build/modern/useField.cjs.map +1 -1
- package/build/modern/useField.d.cts +23 -17
- package/build/modern/useField.d.ts +23 -17
- package/build/modern/useField.js +8 -3
- package/build/modern/useField.js.map +1 -1
- package/build/modern/useForm.cjs.map +1 -1
- package/build/modern/useForm.d.cts +2 -1
- package/build/modern/useForm.d.ts +2 -1
- package/build/modern/useForm.js.map +1 -1
- package/package.json +2 -2
- package/src/types.ts +8 -2
- package/src/useField.tsx +74 -67
- package/src/useForm.tsx +1 -2
package/build/legacy/index.d.cts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
export * from '@tanstack/form-core';
|
2
2
|
export { FormFactory, createFormFactory } from './createFormFactory.cjs';
|
3
3
|
export { FormContext, formContext, provideFormContext, useFormContext } from './formContext.cjs';
|
4
|
-
export { Field, FieldComponent, FieldValue, UseField,
|
4
|
+
export { Field, FieldComponent, FieldValue, UseField, useField } from './useField.cjs';
|
5
5
|
export { useForm } from './useForm.cjs';
|
6
6
|
import 'vue-demi';
|
7
7
|
import './types.cjs';
|
8
|
+
import '@tanstack/vue-store';
|
package/build/legacy/index.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
export * from '@tanstack/form-core';
|
2
2
|
export { FormFactory, createFormFactory } from './createFormFactory.js';
|
3
3
|
export { FormContext, formContext, provideFormContext, useFormContext } from './formContext.js';
|
4
|
-
export { Field, FieldComponent, FieldValue, UseField,
|
4
|
+
export { Field, FieldComponent, FieldValue, UseField, useField } from './useField.js';
|
5
5
|
export { useForm } from './useForm.js';
|
6
6
|
import 'vue-demi';
|
7
7
|
import './types.js';
|
8
|
+
import '@tanstack/vue-store';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TData,\n TFormData,\n TName = unknown extends TFormData ? string : DeepKeys<TFormData>,\n> = FieldOptions<TData, TFormData, TName> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/build/legacy/types.d.cts
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
type ReleaseVersion = 2;
|
1
|
+
import { DeepKeys, FieldOptions } from '@tanstack/form-core';
|
3
2
|
|
4
|
-
|
3
|
+
type UseFieldOptions<TData, TFormData, TName = unknown extends TFormData ? string : DeepKeys<TFormData>> = FieldOptions<TData, TFormData, TName> & {
|
4
|
+
mode?: 'value' | 'array';
|
5
|
+
};
|
6
|
+
|
7
|
+
export { UseFieldOptions };
|
package/build/legacy/types.d.ts
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
type ReleaseVersion = 2;
|
1
|
+
import { DeepKeys, FieldOptions } from '@tanstack/form-core';
|
3
2
|
|
4
|
-
|
3
|
+
type UseFieldOptions<TData, TFormData, TName = unknown extends TFormData ? string : DeepKeys<TFormData>> = FieldOptions<TData, TFormData, TName> & {
|
4
|
+
mode?: 'value' | 'array';
|
5
|
+
};
|
6
|
+
|
7
|
+
export { UseFieldOptions };
|
@@ -31,8 +31,11 @@ var import_formContext = require("./formContext.cjs");
|
|
31
31
|
function useField(opts) {
|
32
32
|
const { formApi, parentFieldName } = (0, import_formContext.useFormContext)();
|
33
33
|
const fieldApi = (() => {
|
34
|
-
const
|
35
|
-
|
34
|
+
const api = new import_form_core.FieldApi({
|
35
|
+
...opts,
|
36
|
+
form: formApi,
|
37
|
+
name: opts.name
|
38
|
+
});
|
36
39
|
api.Field = Field;
|
37
40
|
return api;
|
38
41
|
})();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {\n FieldApi,\n type FieldApiOptions,\n type FormApi,\n} from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<_TData, TFormData, Opts, TData> {\n Field: FieldComponent<TFormData, TData>\n }\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: Narrow<TField> } & UseFieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function useField<\n TData,\n TFormData,\n TName extends unknown extends TFormData\n ? string\n : DeepKeys<TFormData> = unknown extends TFormData\n ? string\n : DeepKeys<TFormData>,\n>(\n opts: UseFieldOptions<TData, TFormData, TName>,\n): {\n api: FieldApi<\n TData,\n TFormData,\n Omit<typeof opts, 'onMount'> & {\n form: FormApi<TFormData>\n }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TFormData,\n Omit<typeof opts, 'onMount'> & {\n form: FormApi<TFormData>\n }\n >['state']\n >\n >\n} {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const fieldApi = (() => {\n const api = new FieldApi({\n ...opts,\n form: formApi,\n name: opts.name,\n } as never)\n\n api.Field = Field as never\n\n return api\n })()\n\n const fieldState = useStore(fieldApi.store, (state) => state)\n\n let cleanup!: () => void\n onMounted(() => {\n cleanup = fieldApi.mount()\n })\n\n onUnmounted(() => {\n cleanup()\n })\n\n watch(\n () => opts,\n () => {\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi } as never)\n },\n )\n\n return { api: fieldApi, state: fieldState } as never\n}\n\nexport type FieldValue<TFormData, TField> = TFormData extends any[]\n ? unknown extends TField\n ? TFormData[number]\n : DeepValue<TFormData[number], TField>\n : DeepValue<TFormData, TField>\n\ntype FieldComponentProps<\n TParentData,\n TFormData,\n TField,\n TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,\n> = (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TField, TFormData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData, TFormData> = <\n // Type of the field\n TField,\n // Name of the field\n TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,\n>(\n fieldOptions: FieldComponentProps<TParentData, TFormData, TField, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<\n TField,\n TFormData,\n FieldApiOptions<TField, TFormData, TName>\n >\n state: FieldApi<\n TField,\n TFormData,\n FieldApiOptions<TField, TFormData, TName>\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TFormData>(\n fieldOptions: UseFieldOptions<TData, TFormData>,\n context: SetupContext,\n ) => {\n const fieldApi = useField({ ...fieldOptions, ...context.attrs })\n\n provideFormContext({\n formApi: fieldApi.api.form,\n parentFieldName: fieldApi.api.name,\n } as never)\n\n return () =>\n context.slots.default!({\n field: fieldApi.api,\n state: fieldApi.state.value,\n })\n },\n { name: 'Field', inheritAttrs: false },\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAIO;AAEP,uBAAyB;AACzB,sBAA+D;AAE/D,yBAAmD;AAiB5C,SAAS,SASd,MAoBA;AAEA,QAAM,EAAE,SAAS,gBAAgB,QAAI,mCAAe;AAEpD,QAAM,YAAY,MAAM;AACtB,UAAM,MAAM,IAAI,0BAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAU;AAEV,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,GAAG;AAEH,QAAM,iBAAa,2BAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAE5D,MAAI;AACJ,iCAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,mCAAY,MAAM;AAChB,YAAQ;AAAA,EACV,CAAC;AAED;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAkDO,IAAM,YAAQ;AAAA,EACnB,CACE,cACA,YACG;AACH,UAAM,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,MAAM,CAAC;AAE/D,+CAAmB;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAChC,CAAU;AAEV,WAAO,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;","names":[]}
|
@@ -1,38 +1,44 @@
|
|
1
|
-
import
|
1
|
+
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
+
import { DeepKeys, FieldApi, FieldApiOptions, Narrow, DeepValue, FormApi } from '@tanstack/form-core';
|
2
3
|
import { SetupContext, SlotsType, Ref } from 'vue-demi';
|
4
|
+
import { UseFieldOptions } from './types.cjs';
|
3
5
|
|
4
6
|
declare module '@tanstack/form-core' {
|
5
|
-
interface FieldApi<
|
6
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<_TData, TFormData, Opts, TData> {
|
8
|
+
Field: FieldComponent<TFormData, TData>;
|
7
9
|
}
|
8
10
|
}
|
9
|
-
interface UseFieldOptions<TData, TFormData> extends FieldOptions<TData, TFormData> {
|
10
|
-
mode?: 'value' | 'array';
|
11
|
-
}
|
12
11
|
type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(opts?: {
|
13
12
|
name: Narrow<TField>;
|
14
13
|
} & UseFieldOptions<DeepValue<TFormData, TField>, TFormData>) => FieldApi<DeepValue<TFormData, TField>, TFormData>;
|
15
|
-
declare function useField<TData, TFormData>(opts: UseFieldOptions<TData, TFormData>): {
|
16
|
-
api: FieldApi<TData, TFormData
|
17
|
-
|
14
|
+
declare function useField<TData, TFormData, TName extends unknown extends TFormData ? string : DeepKeys<TFormData> = unknown extends TFormData ? string : DeepKeys<TFormData>>(opts: UseFieldOptions<TData, TFormData, TName>): {
|
15
|
+
api: FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
16
|
+
form: FormApi<TFormData>;
|
17
|
+
}>;
|
18
|
+
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
+
form: FormApi<TFormData>;
|
20
|
+
}>['state']>>;
|
18
21
|
};
|
19
22
|
type FieldValue<TFormData, TField> = TFormData extends any[] ? unknown extends TField ? TFormData[number] : DeepValue<TFormData[number], TField> : DeepValue<TFormData, TField>;
|
20
|
-
type
|
21
|
-
name?:
|
23
|
+
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = (TParentData extends any[] ? {
|
24
|
+
name?: TName;
|
22
25
|
index: number;
|
23
26
|
} : {
|
24
|
-
name:
|
27
|
+
name: TName;
|
25
28
|
index?: never;
|
26
|
-
})
|
29
|
+
}) & Omit<UseFieldOptions<TField, TFormData, TName>, 'name' | 'index'>;
|
30
|
+
type FieldComponent<TParentData, TFormData> = <TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>>(fieldOptions: FieldComponentProps<TParentData, TFormData, TField, TName>, context: SetupContext<{}, SlotsType<{
|
27
31
|
default: {
|
28
|
-
field: FieldApi<
|
29
|
-
state:
|
32
|
+
field: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>;
|
33
|
+
state: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>['state'];
|
30
34
|
};
|
31
35
|
}>>) => any;
|
32
|
-
declare const Field: <TData, TFormData>(props:
|
36
|
+
declare const Field: <TData, TFormData>(props: _tanstack_form_core.FieldOptions<TData, TFormData, unknown extends TFormData ? string : DeepKeys<TFormData>, unknown extends TData ? DeepValue<TFormData, unknown extends TFormData ? string : DeepKeys<TFormData>> : TData> & {
|
37
|
+
mode?: "value" | "array" | undefined;
|
38
|
+
} & ({
|
33
39
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
34
40
|
} | {
|
35
41
|
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
36
42
|
})) => any;
|
37
43
|
|
38
|
-
export { Field, FieldComponent, FieldValue, UseField,
|
44
|
+
export { Field, FieldComponent, FieldValue, UseField, useField };
|
@@ -1,38 +1,44 @@
|
|
1
|
-
import
|
1
|
+
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
+
import { DeepKeys, FieldApi, FieldApiOptions, Narrow, DeepValue, FormApi } from '@tanstack/form-core';
|
2
3
|
import { SetupContext, SlotsType, Ref } from 'vue-demi';
|
4
|
+
import { UseFieldOptions } from './types.js';
|
3
5
|
|
4
6
|
declare module '@tanstack/form-core' {
|
5
|
-
interface FieldApi<
|
6
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<_TData, TFormData, Opts, TData> {
|
8
|
+
Field: FieldComponent<TFormData, TData>;
|
7
9
|
}
|
8
10
|
}
|
9
|
-
interface UseFieldOptions<TData, TFormData> extends FieldOptions<TData, TFormData> {
|
10
|
-
mode?: 'value' | 'array';
|
11
|
-
}
|
12
11
|
type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(opts?: {
|
13
12
|
name: Narrow<TField>;
|
14
13
|
} & UseFieldOptions<DeepValue<TFormData, TField>, TFormData>) => FieldApi<DeepValue<TFormData, TField>, TFormData>;
|
15
|
-
declare function useField<TData, TFormData>(opts: UseFieldOptions<TData, TFormData>): {
|
16
|
-
api: FieldApi<TData, TFormData
|
17
|
-
|
14
|
+
declare function useField<TData, TFormData, TName extends unknown extends TFormData ? string : DeepKeys<TFormData> = unknown extends TFormData ? string : DeepKeys<TFormData>>(opts: UseFieldOptions<TData, TFormData, TName>): {
|
15
|
+
api: FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
16
|
+
form: FormApi<TFormData>;
|
17
|
+
}>;
|
18
|
+
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
+
form: FormApi<TFormData>;
|
20
|
+
}>['state']>>;
|
18
21
|
};
|
19
22
|
type FieldValue<TFormData, TField> = TFormData extends any[] ? unknown extends TField ? TFormData[number] : DeepValue<TFormData[number], TField> : DeepValue<TFormData, TField>;
|
20
|
-
type
|
21
|
-
name?:
|
23
|
+
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = (TParentData extends any[] ? {
|
24
|
+
name?: TName;
|
22
25
|
index: number;
|
23
26
|
} : {
|
24
|
-
name:
|
27
|
+
name: TName;
|
25
28
|
index?: never;
|
26
|
-
})
|
29
|
+
}) & Omit<UseFieldOptions<TField, TFormData, TName>, 'name' | 'index'>;
|
30
|
+
type FieldComponent<TParentData, TFormData> = <TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>>(fieldOptions: FieldComponentProps<TParentData, TFormData, TField, TName>, context: SetupContext<{}, SlotsType<{
|
27
31
|
default: {
|
28
|
-
field: FieldApi<
|
29
|
-
state:
|
32
|
+
field: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>;
|
33
|
+
state: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>['state'];
|
30
34
|
};
|
31
35
|
}>>) => any;
|
32
|
-
declare const Field: <TData, TFormData>(props:
|
36
|
+
declare const Field: <TData, TFormData>(props: _tanstack_form_core.FieldOptions<TData, TFormData, unknown extends TFormData ? string : DeepKeys<TFormData>, unknown extends TData ? DeepValue<TFormData, unknown extends TFormData ? string : DeepKeys<TFormData>> : TData> & {
|
37
|
+
mode?: "value" | "array" | undefined;
|
38
|
+
} & ({
|
33
39
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
34
40
|
} | {
|
35
41
|
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
36
42
|
})) => any;
|
37
43
|
|
38
|
-
export { Field, FieldComponent, FieldValue, UseField,
|
44
|
+
export { Field, FieldComponent, FieldValue, UseField, useField };
|
package/build/legacy/useField.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
// src/useField.tsx
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
FieldApi
|
4
|
+
} from "@tanstack/form-core";
|
3
5
|
import { useStore } from "@tanstack/vue-store";
|
4
6
|
import { defineComponent, onMounted, onUnmounted, watch } from "vue-demi";
|
5
7
|
import { provideFormContext, useFormContext } from "./formContext.js";
|
6
8
|
function useField(opts) {
|
7
9
|
const { formApi, parentFieldName } = useFormContext();
|
8
10
|
const fieldApi = (() => {
|
9
|
-
const
|
10
|
-
|
11
|
+
const api = new FieldApi({
|
12
|
+
...opts,
|
13
|
+
form: formApi,
|
14
|
+
name: opts.name
|
15
|
+
});
|
11
16
|
api.Field = Field;
|
12
17
|
return api;
|
13
18
|
})();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {\n FieldApi,\n type FieldApiOptions,\n type FormApi,\n} from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<_TData, TFormData, Opts, TData> {\n Field: FieldComponent<TFormData, TData>\n }\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: Narrow<TField> } & UseFieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function useField<\n TData,\n TFormData,\n TName extends unknown extends TFormData\n ? string\n : DeepKeys<TFormData> = unknown extends TFormData\n ? string\n : DeepKeys<TFormData>,\n>(\n opts: UseFieldOptions<TData, TFormData, TName>,\n): {\n api: FieldApi<\n TData,\n TFormData,\n Omit<typeof opts, 'onMount'> & {\n form: FormApi<TFormData>\n }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TFormData,\n Omit<typeof opts, 'onMount'> & {\n form: FormApi<TFormData>\n }\n >['state']\n >\n >\n} {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const fieldApi = (() => {\n const api = new FieldApi({\n ...opts,\n form: formApi,\n name: opts.name,\n } as never)\n\n api.Field = Field as never\n\n return api\n })()\n\n const fieldState = useStore(fieldApi.store, (state) => state)\n\n let cleanup!: () => void\n onMounted(() => {\n cleanup = fieldApi.mount()\n })\n\n onUnmounted(() => {\n cleanup()\n })\n\n watch(\n () => opts,\n () => {\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi } as never)\n },\n )\n\n return { api: fieldApi, state: fieldState } as never\n}\n\nexport type FieldValue<TFormData, TField> = TFormData extends any[]\n ? unknown extends TField\n ? TFormData[number]\n : DeepValue<TFormData[number], TField>\n : DeepValue<TFormData, TField>\n\ntype FieldComponentProps<\n TParentData,\n TFormData,\n TField,\n TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,\n> = (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TField, TFormData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData, TFormData> = <\n // Type of the field\n TField,\n // Name of the field\n TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,\n>(\n fieldOptions: FieldComponentProps<TParentData, TFormData, TField, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<\n TField,\n TFormData,\n FieldApiOptions<TField, TFormData, TName>\n >\n state: FieldApi<\n TField,\n TFormData,\n FieldApiOptions<TField, TFormData, TName>\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TFormData>(\n fieldOptions: UseFieldOptions<TData, TFormData>,\n context: SetupContext,\n ) => {\n const fieldApi = useField({ ...fieldOptions, ...context.attrs })\n\n provideFormContext({\n formApi: fieldApi.api.form,\n parentFieldName: fieldApi.api.name,\n } as never)\n\n return () =>\n context.slots.default!({\n field: fieldApi.api,\n state: fieldApi.state.value,\n })\n },\n { name: 'Field', inheritAttrs: false },\n)\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,aAAa,aAAa;AAE/D,SAAS,oBAAoB,sBAAsB;AAiB5C,SAAS,SASd,MAoBA;AAEA,QAAM,EAAE,SAAS,gBAAgB,IAAI,eAAe;AAEpD,QAAM,YAAY,MAAM;AACtB,UAAM,MAAM,IAAI,SAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAU;AAEV,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,GAAG;AAEH,QAAM,aAAa,SAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAE5D,MAAI;AACJ,YAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,cAAY,MAAM;AAChB,YAAQ;AAAA,EACV,CAAC;AAED;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAkDO,IAAM,QAAQ;AAAA,EACnB,CACE,cACA,YACG;AACH,UAAM,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,MAAM,CAAC;AAE/D,uBAAmB;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAChC,CAAU;AAEV,WAAO,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const formApi = (() => {\n const api = new FormApi<TData>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi })\n }\n api.Field = Field as never\n api.useField = useField as never\n api.useStore = (selector) => {\n return useStore(api.store as never, selector as never) as never\n }\n api.Subscribe = defineComponent(\n (props, context) => {\n const allProps = { ...props, ...context.attrs }\n const selector = allProps.selector ?? ((state) => state)\n const data = useStore(api.store as never, selector as never)\n return () => context.slots.default!(data.value)\n },\n {\n name: 'Subscribe',\n inheritAttrs: false,\n },\n )\n\n return api\n })()\n\n // formApi.useStore((state) => state.isSubmitting)\n formApi.update(opts)\n\n return formApi as never\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0D;AAC1D,uBAAuC;AACvC,sBAAoE;AACpE,yBAAmC;AACnC,sBAKO;AAwBA,SAAS,QAAe,MAA2C;AACxE,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,yBAAe,IAAI;AAEnC,QAAI,eAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,mDAAmB,EAAE,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,iDAAmB,EAAE,QAAQ,CAAC;AAAA,IAChC;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAAC,aAAa;AAC3B,iBAAO,2BAAS,IAAI,OAAgB,QAAiB;AAAA,IACvD;AACA,QAAI,gBAAY;AAAA,MACd,CAAC,OAAO,YAAY;AAClB,cAAM,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,MAAM;AAC9C,cAAM,WAAW,SAAS,aAAa,CAAC,UAAU;AAClD,cAAM,WAAO,2BAAS,IAAI,OAAgB,QAAiB;AAC3D,eAAO,MAAM,QAAQ,MAAM,QAAS,KAAK,KAAK;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG;AAGH,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;","names":[]}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
|
2
|
+
import { NoInfer } from '@tanstack/vue-store';
|
2
3
|
import { FieldComponent, UseField } from './useField.cjs';
|
3
4
|
import { SetupContext, EmitsOptions, SlotsType } from 'vue-demi';
|
4
|
-
import
|
5
|
+
import './types.cjs';
|
5
6
|
|
6
7
|
declare module '@tanstack/form-core' {
|
7
8
|
interface FormApi<TFormData> {
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
|
2
|
+
import { NoInfer } from '@tanstack/vue-store';
|
2
3
|
import { FieldComponent, UseField } from './useField.js';
|
3
4
|
import { SetupContext, EmitsOptions, SlotsType } from 'vue-demi';
|
4
|
-
import
|
5
|
+
import './types.js';
|
5
6
|
|
6
7
|
declare module '@tanstack/form-core' {
|
7
8
|
interface FormApi<TFormData> {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const formApi = (() => {\n const api = new FormApi<TData>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi })\n }\n api.Field = Field as never\n api.useField = useField as never\n api.useStore = (selector) => {\n return useStore(api.store as never, selector as never) as never\n }\n api.Subscribe = defineComponent(\n (props, context) => {\n const allProps = { ...props, ...context.attrs }\n const selector = allProps.selector ?? ((state) => state)\n const data = useStore(api.store as never, selector as never)\n return () => context.slots.default!(data.value)\n },\n {\n name: 'Subscribe',\n inheritAttrs: false,\n },\n )\n\n return api\n })()\n\n // formApi.useStore((state) => state.isSubmitting)\n formApi.update(opts)\n\n return formApi as never\n}\n"],"mappings":";AAAA,SAAS,eAAiD;AAC1D,SAAuB,gBAAgB;AACvC,SAA6C,OAAO,gBAAgB;AACpE,SAAS,0BAA0B;AACnC;AAAA,EAIE;AAAA,OACK;AAwBA,SAAS,QAAe,MAA2C;AACxE,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,QAAe,IAAI;AAEnC,QAAI,WAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,2BAAmB,EAAE,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,yBAAmB,EAAE,QAAQ,CAAC;AAAA,IAChC;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAAC,aAAa;AAC3B,aAAO,SAAS,IAAI,OAAgB,QAAiB;AAAA,IACvD;AACA,QAAI,YAAY;AAAA,MACd,CAAC,OAAO,YAAY;AAClB,cAAM,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,MAAM;AAC9C,cAAM,WAAW,SAAS,aAAa,CAAC,UAAU;AAClD,cAAM,OAAO,SAAS,IAAI,OAAgB,QAAiB;AAC3D,eAAO,MAAM,QAAQ,MAAM,QAAS,KAAK,KAAK;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG;AAGH,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;","names":[]}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { FormApi, FormOptions } from '@tanstack/form-core';
|
2
|
+
import { type UseField, type FieldComponent } from './useField';
|
3
|
+
export type FormFactory<TFormData> = {
|
4
|
+
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
5
|
+
useField: UseField<TFormData>;
|
6
|
+
Field: FieldComponent<TFormData, TFormData>;
|
7
|
+
};
|
8
|
+
export declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Field, useField } from './useField';
|
2
|
+
import { useForm } from './useForm';
|
3
|
+
export function createFormFactory(defaultOpts) {
|
4
|
+
return {
|
5
|
+
useForm: (opts) => {
|
6
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
7
|
+
return useForm(formOptions);
|
8
|
+
},
|
9
|
+
useField: useField,
|
10
|
+
Field: Field,
|
11
|
+
};
|
12
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { FormApi } from '@tanstack/form-core';
|
2
|
+
export type FormContext = {
|
3
|
+
formApi: FormApi<any>;
|
4
|
+
parentFieldName?: string;
|
5
|
+
} | null;
|
6
|
+
export declare const formContext: unique symbol;
|
7
|
+
export declare function provideFormContext(val: FormContext): void;
|
8
|
+
export declare function useFormContext(): {
|
9
|
+
formApi: FormApi<any>;
|
10
|
+
parentFieldName?: string | undefined;
|
11
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { inject, provide } from 'vue-demi';
|
2
|
+
export const formContext = Symbol('FormContext');
|
3
|
+
export function provideFormContext(val) {
|
4
|
+
provide(formContext, val);
|
5
|
+
}
|
6
|
+
export function useFormContext() {
|
7
|
+
const formApi = inject(formContext);
|
8
|
+
if (!formApi) {
|
9
|
+
throw new Error(`You are trying to use the form API outside of a form!`);
|
10
|
+
}
|
11
|
+
return formApi;
|
12
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
/// <reference lib="dom" />
|
2
|
+
import { defineComponent } from 'vue-demi';
|
3
|
+
import { render, waitFor } from '@testing-library/vue';
|
4
|
+
import '@testing-library/jest-dom';
|
5
|
+
import { createFormFactory, provideFormContext, } from '../index';
|
6
|
+
import userEvent from '@testing-library/user-event';
|
7
|
+
import { sleep } from './utils';
|
8
|
+
const user = userEvent.setup();
|
9
|
+
describe('useField', () => {
|
10
|
+
it('should allow to set default value', async () => {
|
11
|
+
const formFactory = createFormFactory();
|
12
|
+
const Comp = defineComponent(() => {
|
13
|
+
const form = formFactory.useForm();
|
14
|
+
provideFormContext({ formApi: form });
|
15
|
+
return () => (<form.Field name="firstName" defaultValue="FirstName">
|
16
|
+
{({ field }) => (<input data-testid={'fieldinput'} value={field.state.value} onBlur={field.handleBlur} onInput={(e) => field.handleChange(e.target.value)}/>)}
|
17
|
+
</form.Field>);
|
18
|
+
});
|
19
|
+
const { getByTestId } = render(Comp);
|
20
|
+
const input = getByTestId('fieldinput');
|
21
|
+
await waitFor(() => expect(input).toHaveValue('FirstName'));
|
22
|
+
});
|
23
|
+
it('should not validate on change if isTouched is false', async () => {
|
24
|
+
const error = 'Please enter a different value';
|
25
|
+
const formFactory = createFormFactory();
|
26
|
+
const Comp = defineComponent(() => {
|
27
|
+
const form = formFactory.useForm();
|
28
|
+
provideFormContext({ formApi: form });
|
29
|
+
return () => (<form.Field name="firstName" onChange={(value) => (value === 'other' ? error : undefined)}>
|
30
|
+
{({ field }) => (<div>
|
31
|
+
<input data-testid="fieldinput" name={field.name} value={field.state.value} onBlur={field.handleBlur} onInput={(e) => field.setValue(e.target.value)}/>
|
32
|
+
<p>{field.getMeta().errors}</p>
|
33
|
+
</div>)}
|
34
|
+
</form.Field>);
|
35
|
+
});
|
36
|
+
const { getByTestId, queryByText } = render(Comp);
|
37
|
+
const input = getByTestId('fieldinput');
|
38
|
+
await user.type(input, 'other');
|
39
|
+
expect(queryByText(error)).not.toBeInTheDocument();
|
40
|
+
});
|
41
|
+
it('should validate on change if isTouched is true', async () => {
|
42
|
+
const error = 'Please enter a different value';
|
43
|
+
const formFactory = createFormFactory();
|
44
|
+
const Comp = defineComponent(() => {
|
45
|
+
const form = formFactory.useForm();
|
46
|
+
provideFormContext({ formApi: form });
|
47
|
+
return () => (<form.Field name="firstName" onChange={(value) => (value === 'other' ? error : undefined)}>
|
48
|
+
{({ field }) => (<div>
|
49
|
+
<input data-testid="fieldinput" name={field.name} value={field.state.value} onBlur={field.handleBlur} onInput={(e) => field.handleChange(e.target.value)}/>
|
50
|
+
<p>{field.getMeta().errors}</p>
|
51
|
+
</div>)}
|
52
|
+
</form.Field>);
|
53
|
+
});
|
54
|
+
const { getByTestId, getByText, queryByText } = render(Comp);
|
55
|
+
const input = getByTestId('fieldinput');
|
56
|
+
expect(queryByText(error)).not.toBeInTheDocument();
|
57
|
+
await user.type(input, 'other');
|
58
|
+
expect(getByText(error)).toBeInTheDocument();
|
59
|
+
});
|
60
|
+
it('should validate async on change', async () => {
|
61
|
+
const error = 'Please enter a different value';
|
62
|
+
const formFactory = createFormFactory();
|
63
|
+
const Comp = defineComponent(() => {
|
64
|
+
const form = formFactory.useForm();
|
65
|
+
provideFormContext({ formApi: form });
|
66
|
+
return () => (<form.Field name="firstName" defaultMeta={{ isTouched: true }} onChangeAsync={async () => {
|
67
|
+
await sleep(10);
|
68
|
+
return error;
|
69
|
+
}}>
|
70
|
+
{({ field }) => (<div>
|
71
|
+
<input data-testid="fieldinput" name={field.name} value={field.state.value} onBlur={field.handleBlur} onInput={(e) => field.handleChange(e.target.value)}/>
|
72
|
+
<p>{field.getMeta().errors}</p>
|
73
|
+
</div>)}
|
74
|
+
</form.Field>);
|
75
|
+
});
|
76
|
+
const { getByTestId, getByText, queryByText } = render(Comp);
|
77
|
+
const input = getByTestId('fieldinput');
|
78
|
+
expect(queryByText(error)).not.toBeInTheDocument();
|
79
|
+
await user.type(input, 'other');
|
80
|
+
await waitFor(() => getByText(error));
|
81
|
+
expect(getByText(error)).toBeInTheDocument();
|
82
|
+
});
|
83
|
+
it('should validate async on change with debounce', async () => {
|
84
|
+
const mockFn = vi.fn();
|
85
|
+
const error = 'Please enter a different value';
|
86
|
+
const formFactory = createFormFactory();
|
87
|
+
const Comp = defineComponent(() => {
|
88
|
+
const form = formFactory.useForm();
|
89
|
+
provideFormContext({ formApi: form });
|
90
|
+
return () => (<form.Field name="firstName" defaultMeta={{ isTouched: true }} onChangeAsyncDebounceMs={100} onChangeAsync={async () => {
|
91
|
+
mockFn();
|
92
|
+
await sleep(10);
|
93
|
+
return error;
|
94
|
+
}}>
|
95
|
+
{({ field }) => (<div>
|
96
|
+
<input data-testid="fieldinput" name={field.name} value={field.state.value} onBlur={field.handleBlur} onInput={(e) => field.handleChange(e.target.value)}/>
|
97
|
+
<p>{field.getMeta().errors}</p>
|
98
|
+
</div>)}
|
99
|
+
</form.Field>);
|
100
|
+
});
|
101
|
+
const { getByTestId, getByText } = render(<Comp />);
|
102
|
+
const input = getByTestId('fieldinput');
|
103
|
+
await user.type(input, 'other');
|
104
|
+
// mockFn will have been called 5 times without onChangeAsyncDebounceMs
|
105
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
106
|
+
await waitFor(() => getByText(error));
|
107
|
+
expect(getByText(error)).toBeInTheDocument();
|
108
|
+
});
|
109
|
+
});
|