diff --git a/docs/framework/angular/guides/validation.md b/docs/framework/angular/guides/validation.md index d9d72352a..4b73245d6 100644 --- a/docs/framework/angular/guides/validation.md +++ b/docs/framework/angular/guides/validation.md @@ -204,6 +204,42 @@ export class AppComponent { } ``` +It's worth mentioning that our `errors` array and the `errorMap` matches the types returned by the validators. This means that: + +```angular-ts +@Component({ + selector: 'app-root', + standalone: true, + imports: [TanStackField], + template: ` + + + + + @if (!age.api.state.meta.errorMap['onChange']?.isOldEnough) { + The user is not old enough + } + + `, +}) +export class AppComponent { + ageValidator: FieldValidateFn = ({ value }) => + value < 13 ? 'You must be 13 to make an account' : undefined + + // ... +} +``` + + + + ## Validation at field level vs at form level As shown above, each `[tanstackField]` accepts its own validation rules via the `onChange`, `onBlur` etc... callbacks. It is also possible to define validation rules at the form level (as opposed to field by field) by passing similar callbacks to the `injectForm()` function. diff --git a/docs/framework/angular/reference/classes/tanstackfield.md b/docs/framework/angular/reference/classes/tanstackfield.md index 8d8f6dbaa..b3a84cdd8 100644 --- a/docs/framework/angular/reference/classes/tanstackfield.md +++ b/docs/framework/angular/reference/classes/tanstackfield.md @@ -3,7 +3,9 @@ id: TanStackField title: TanStackField --- -# Class: TanStackField\ + + +# Class: TanStackField\ Defined in: [tanstack-field.directive.ts:25](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L25) @@ -21,34 +23,64 @@ Defined in: [tanstack-field.directive.ts:25](https://github.com/TanStack/form/bl • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Implements - `OnInit` - `OnChanges` - `OnDestroy` -- `FieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +- `FieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ## Constructors ### new TanStackField() ```ts -new TanStackField(): TanStackField +new TanStackField(): TanStackField ``` #### Returns -[`TanStackField`](tanstackfield.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +[`TanStackField`](tanstackfield.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Properties ### api ```ts -api: FieldApi; +api: FieldApi; ``` -Defined in: [tanstack-field.directive.ts:62](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L62) +Defined in: [tanstack-field.directive.ts:111](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L111) *** @@ -58,7 +90,7 @@ Defined in: [tanstack-field.directive.ts:62](https://github.com/TanStack/form/bl optional asyncAlways: boolean; ``` -Defined in: [tanstack-field.directive.ts:48](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L48) +Defined in: [tanstack-field.directive.ts:76](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L76) If `true`, always run async validation, even if there are errors emitted during synchronous validation. @@ -76,7 +108,7 @@ FieldOptions.asyncAlways optional asyncDebounceMs: number; ``` -Defined in: [tanstack-field.directive.ts:47](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L47) +Defined in: [tanstack-field.directive.ts:75](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L75) The default time to debounce async validation if there is not a more specific debounce time passed. @@ -94,7 +126,7 @@ FieldOptions.asyncDebounceMs optional defaultMeta: Partial; ``` -Defined in: [tanstack-field.directive.ts:60](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L60) +Defined in: [tanstack-field.directive.ts:109](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L109) An optional object with default metadata for the field. @@ -112,7 +144,7 @@ FieldOptions.defaultMeta optional defaultValue: NoInfer; ``` -Defined in: [tanstack-field.directive.ts:46](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L46) +Defined in: [tanstack-field.directive.ts:74](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L74) An optional default value for the field. @@ -130,7 +162,7 @@ FieldOptions.defaultValue optional listeners: NoInfer>; ``` -Defined in: [tanstack-field.directive.ts:57](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L57) +Defined in: [tanstack-field.directive.ts:106](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L106) A list of listeners which attach to the corresponding events @@ -148,7 +180,7 @@ FieldOptions.listeners name: TName; ``` -Defined in: [tanstack-field.directive.ts:42](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L42) +Defined in: [tanstack-field.directive.ts:70](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L70) The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -163,10 +195,10 @@ FieldOptions.name ### tanstackField ```ts -tanstackField: FormApi; +tanstackField: FormApi; ``` -Defined in: [tanstack-field.directive.ts:50](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L50) +Defined in: [tanstack-field.directive.ts:78](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L78) *** @@ -176,7 +208,7 @@ Defined in: [tanstack-field.directive.ts:50](https://github.com/TanStack/form/bl optional unmount: () => void; ``` -Defined in: [tanstack-field.directive.ts:78](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L78) +Defined in: [tanstack-field.directive.ts:169](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L169) #### Returns @@ -190,7 +222,7 @@ Defined in: [tanstack-field.directive.ts:78](https://github.com/TanStack/form/bl optional validatorAdapter: TFieldValidator; ``` -Defined in: [tanstack-field.directive.ts:49](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L49) +Defined in: [tanstack-field.directive.ts:77](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L77) A validator provided by an extension, like `yupValidator` from `@tanstack/yup-form-adapter` @@ -205,10 +237,10 @@ FieldOptions.validatorAdapter ### validators? ```ts -optional validators: NoInfer>; +optional validators: NoInfer>; ``` -Defined in: [tanstack-field.directive.ts:54](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L54) +Defined in: [tanstack-field.directive.ts:90](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L90) A list of validators to pass to the field @@ -226,7 +258,7 @@ FieldOptions.validators ngOnChanges(): void ``` -Defined in: [tanstack-field.directive.ts:90](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L90) +Defined in: [tanstack-field.directive.ts:181](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L181) A callback method that is invoked immediately after the default change detector has checked data-bound properties @@ -251,7 +283,7 @@ OnChanges.ngOnChanges ngOnDestroy(): void ``` -Defined in: [tanstack-field.directive.ts:86](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L86) +Defined in: [tanstack-field.directive.ts:177](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L177) A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed. @@ -274,7 +306,7 @@ OnDestroy.ngOnDestroy ngOnInit(): void ``` -Defined in: [tanstack-field.directive.ts:80](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L80) +Defined in: [tanstack-field.directive.ts:171](https://github.com/TanStack/form/blob/main/packages/angular-form/src/tanstack-field.directive.ts#L171) A callback method that is invoked immediately after the default change detector has checked the directive's diff --git a/docs/framework/angular/reference/functions/injectform.md b/docs/framework/angular/reference/functions/injectform.md index 05b89cd61..265548a1e 100644 --- a/docs/framework/angular/reference/functions/injectform.md +++ b/docs/framework/angular/reference/functions/injectform.md @@ -3,10 +3,12 @@ id: injectForm title: injectForm --- + + # Function: injectForm() ```ts -function injectForm(opts?): FormApi +function injectForm(opts?): FormApi ``` Defined in: [inject-form.ts:5](https://github.com/TanStack/form/blob/main/packages/angular-form/src/inject-form.ts#L5) @@ -17,12 +19,28 @@ Defined in: [inject-form.ts:5](https://github.com/TanStack/form/blob/main/packag • **TFormValidator** *extends* `undefined` \| `Validator`\<`TFormData`, `unknown`\> = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + ## Parameters ### opts? -`FormOptions`\<`TFormData`, `TFormValidator`\> +`FormOptions`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ## Returns -`FormApi`\<`TFormData`, `TFormValidator`\> +`FormApi`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> diff --git a/docs/framework/angular/reference/functions/injectstore.md b/docs/framework/angular/reference/functions/injectstore.md index d66d6302a..98d4c51b8 100644 --- a/docs/framework/angular/reference/functions/injectstore.md +++ b/docs/framework/angular/reference/functions/injectstore.md @@ -3,10 +3,12 @@ id: injectStore title: injectStore --- + + # Function: injectStore() ```ts -function injectStore(form, selector?): Signal +function injectStore(form, selector?): Signal ``` Defined in: [inject-store.ts:4](https://github.com/TanStack/form/blob/main/packages/angular-form/src/inject-store.ts#L4) @@ -17,13 +19,29 @@ Defined in: [inject-store.ts:4](https://github.com/TanStack/form/blob/main/packa • **TFormValidator** *extends* `undefined` \| `Validator`\<`TFormData`, `unknown`\> = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + • **TSelected** = `NoInfer`\<`FormState`\<`TFormData`\>\> ## Parameters ### form -`FormApi`\<`TFormData`, `TFormValidator`\> +`FormApi`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ### selector? diff --git a/docs/framework/angular/reference/index.md b/docs/framework/angular/reference/index.md index aab1d7b1d..3110ff697 100644 --- a/docs/framework/angular/reference/index.md +++ b/docs/framework/angular/reference/index.md @@ -3,6 +3,8 @@ id: "@tanstack/angular-form" title: "@tanstack/angular-form" --- + + # @tanstack/angular-form ## Classes diff --git a/docs/framework/lit/reference/classes/tanstackformcontroller.md b/docs/framework/lit/reference/classes/tanstackformcontroller.md index b5be60c77..08e568bec 100644 --- a/docs/framework/lit/reference/classes/tanstackformcontroller.md +++ b/docs/framework/lit/reference/classes/tanstackformcontroller.md @@ -3,9 +3,11 @@ id: TanStackFormController title: TanStackFormController --- -# Class: TanStackFormController\ + -Defined in: [tanstack-form-controller.ts:81](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L81) +# Class: TanStackFormController\ + +Defined in: [tanstack-form-controller.ts:181](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L181) ## Type Parameters @@ -13,6 +15,22 @@ Defined in: [tanstack-form-controller.ts:81](https://github.com/TanStack/form/bl • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Implements - `ReactiveController` @@ -22,10 +40,10 @@ Defined in: [tanstack-form-controller.ts:81](https://github.com/TanStack/form/bl ### new TanStackFormController() ```ts -new TanStackFormController(host, config?): TanStackFormController +new TanStackFormController(host, config?): TanStackFormController ``` -Defined in: [tanstack-form-controller.ts:93](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L93) +Defined in: [tanstack-form-controller.ts:212](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L212) #### Parameters @@ -35,31 +53,31 @@ Defined in: [tanstack-form-controller.ts:93](https://github.com/TanStack/form/bl ##### config? -`FormOptions`\<`TParentData`, `TFormValidator`\> +`FormOptions`\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Returns -[`TanStackFormController`](tanstackformcontroller.md)\<`TParentData`, `TFormValidator`\> +[`TanStackFormController`](tanstackformcontroller.md)\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Properties ### api ```ts -api: FormApi; +api: FormApi; ``` -Defined in: [tanstack-form-controller.ts:91](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L91) +Defined in: [tanstack-form-controller.ts:199](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L199) ## Methods ### field() ```ts -field(fieldConfig, render): object +field(fieldConfig, render): object ``` -Defined in: [tanstack-form-controller.ts:112](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L112) +Defined in: [tanstack-form-controller.ts:253](https://github.com/TanStack/form/blob/main/packages/lit-form/src/tanstack-form-controller.ts#L253) #### Type Parameters @@ -71,15 +89,29 @@ Defined in: [tanstack-form-controller.ts:112](https://github.com/TanStack/form/b • **TData** = `DeepValue`\<`TParentData`, `TName`, `IsNullable`\<`TParentData`\>\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + #### Parameters ##### fieldConfig -`FieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`FieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ##### render -`renderCallback`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`renderCallback`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Returns @@ -100,13 +132,13 @@ form: FormApi; ###### values.options ```ts -options: FieldOptions; +options: FieldOptions; ``` ###### values.render ```ts -render: renderCallback; +render: renderCallback; ``` *** @@ -117,7 +149,7 @@ render: renderCallback + # @tanstack/lit-form ## Classes diff --git a/docs/framework/react/guides/basic-concepts.md b/docs/framework/react/guides/basic-concepts.md index a8528eb4f..4371617e3 100644 --- a/docs/framework/react/guides/basic-concepts.md +++ b/docs/framework/react/guides/basic-concepts.md @@ -38,7 +38,7 @@ const form = useForm({ You may also create a form instance without using `formOptions` by using the standalone `useForm` API: ```tsx -const form = useForm({ +const form = useForm({ onSubmit: async ({ value }) => { // Do something with form data console.log(value) @@ -47,7 +47,7 @@ const form = useForm({ firstName: '', lastName: '', hobbies: [], - }, + } as Person, }) ``` diff --git a/docs/framework/react/guides/validation.md b/docs/framework/react/guides/validation.md index e8a9ff26f..6b471801d 100644 --- a/docs/framework/react/guides/validation.md +++ b/docs/framework/react/guides/validation.md @@ -150,6 +150,31 @@ Or use the `errorMap` property to access the specific error you're looking for: ``` +It's worth mentioning that our `errors` array and the `errorMap` matches the types returned by the validators. This means that: + +```tsx + + value < 13 ? {isOldEnough: false} : undefined, + }} +> + {(field) => ( + <> + {/* ... */} + {/* errorMap.onChange is type `{isOldEnough: false} | undefined` */} + {/* meta.errors is type `Array<{isOldEnough: false} | undefined>` */} + {!field.state.meta.errorMap['onChange']?.isOldEnough ? ( + The user is not old enough + ) : null} + + )} + +``` + + + ## Validation at field level vs at form level As shown above, each `` accepts its own validation rules via the `onChange`, `onBlur` etc... callbacks. It is also possible to define validation rules at the form level (as opposed to field by field) by passing similar callbacks to the `useForm()` hook. diff --git a/docs/framework/react/reference/functions/field.md b/docs/framework/react/reference/functions/field.md index 908bd0d99..6395c20d1 100644 --- a/docs/framework/react/reference/functions/field.md +++ b/docs/framework/react/reference/functions/field.md @@ -3,13 +3,15 @@ id: Field title: Field --- + + # Function: Field() ```ts -function Field(__namedParameters): ReactNode +function Field(__namedParameters): ReactNode ``` -Defined in: [packages/react-form/src/useField.tsx:164](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L164) +Defined in: [packages/react-form/src/useField.tsx:339](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L339) A function component that takes field options and a render function as children and returns a React component. @@ -29,11 +31,39 @@ The `Field` component uses the `useField` hook internally to manage the field in • **TData** = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + ## Parameters ### \_\_namedParameters -`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\> ## Returns diff --git a/docs/framework/react/reference/functions/usefield.md b/docs/framework/react/reference/functions/usefield.md index 72bc66835..cea1825ca 100644 --- a/docs/framework/react/reference/functions/usefield.md +++ b/docs/framework/react/reference/functions/usefield.md @@ -3,13 +3,15 @@ id: useField title: useField --- + + # Function: useField() ```ts -function useField(opts): FieldApi & ReactFieldApi +function useField(opts): FieldApi & ReactFieldApi ``` -Defined in: [packages/react-form/src/useField.tsx:50](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L50) +Defined in: [packages/react-form/src/useField.tsx:121](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L121) A hook for managing a field in a form. @@ -27,16 +29,44 @@ A hook for managing a field in a form. • **TData** = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + ## Parameters ### opts -`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\> An object with field options. ## Returns -`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> & `ReactFieldApi`\<`TParentData`, `TFormValidator`\> +`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\> & `ReactFieldApi`\<`TParentData`, `TFormValidator`\> The `FieldApi` instance for the specified field. diff --git a/docs/framework/react/reference/functions/useform.md b/docs/framework/react/reference/functions/useform.md index 826335c33..757c5ad26 100644 --- a/docs/framework/react/reference/functions/useform.md +++ b/docs/framework/react/reference/functions/useform.md @@ -3,13 +3,15 @@ id: useForm title: useForm --- + + # Function: useForm() ```ts -function useForm(opts?): ReactFormExtendedApi +function useForm(opts?): ReactFormExtendedApi ``` -Defined in: [packages/react-form/src/useForm.tsx:57](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L57) +Defined in: [packages/react-form/src/useForm.tsx:134](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L134) A custom React Hook that returns an extended instance of the `FormApi` class. @@ -21,12 +23,26 @@ This API encapsulates all the necessary functionalities related to the form. It • **TFormValidator** *extends* `undefined` \| `Validator`\<`TFormData`, `unknown`\> = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### opts? -`FormOptions`\<`TFormData`, `TFormValidator`\> +`FormOptions`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ## Returns -[`ReactFormExtendedApi`](../type-aliases/reactformextendedapi.md)\<`TFormData`, `TFormValidator`\> +[`ReactFormExtendedApi`](../type-aliases/reactformextendedapi.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> diff --git a/docs/framework/react/reference/functions/usestore.md b/docs/framework/react/reference/functions/usestore.md index 76f60a8b8..2b982db00 100644 --- a/docs/framework/react/reference/functions/usestore.md +++ b/docs/framework/react/reference/functions/usestore.md @@ -3,6 +3,8 @@ id: useStore title: useStore --- + + # Function: useStore() ## Call Signature diff --git a/docs/framework/react/reference/functions/usetransform.md b/docs/framework/react/reference/functions/usetransform.md index 737c8c8af..2979e7179 100644 --- a/docs/framework/react/reference/functions/usetransform.md +++ b/docs/framework/react/reference/functions/usetransform.md @@ -3,10 +3,12 @@ id: useTransform title: useTransform --- + + # Function: useTransform() ```ts -function useTransform(fn, deps): FormTransform +function useTransform(fn, deps): FormTransform ``` Defined in: [packages/react-form/src/useTransform.ts:3](https://github.com/TanStack/form/blob/main/packages/react-form/src/useTransform.ts#L3) @@ -17,11 +19,25 @@ Defined in: [packages/react-form/src/useTransform.ts:3](https://github.com/TanSt • **TFormValidator** *extends* `undefined` \| `Validator`\<`TFormData`, `unknown`\> = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### fn -(`formBase`) => `FormApi`\<`TFormData`, `TFormValidator`\> +(`formBase`) => `FormApi`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ### deps @@ -29,4 +45,4 @@ Defined in: [packages/react-form/src/useTransform.ts:3](https://github.com/TanSt ## Returns -`FormTransform`\<`TFormData`, `TFormValidator`\> +`FormTransform`\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> diff --git a/docs/framework/react/reference/index.md b/docs/framework/react/reference/index.md index 599a63e0b..b9c06deaf 100644 --- a/docs/framework/react/reference/index.md +++ b/docs/framework/react/reference/index.md @@ -3,6 +3,8 @@ id: "@tanstack/react-form" title: "@tanstack/react-form" --- + + # @tanstack/react-form ## Interfaces diff --git a/docs/framework/react/reference/interfaces/reactformapi.md b/docs/framework/react/reference/interfaces/reactformapi.md index b53804b8d..9837eabc2 100644 --- a/docs/framework/react/reference/interfaces/reactformapi.md +++ b/docs/framework/react/reference/interfaces/reactformapi.md @@ -3,9 +3,11 @@ id: ReactFormApi title: ReactFormApi --- -# Interface: ReactFormApi\ + -Defined in: [packages/react-form/src/useForm.tsx:14](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L14) +# Interface: ReactFormApi\ + +Defined in: [packages/react-form/src/useForm.tsx:20](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L20) Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm` @@ -15,15 +17,29 @@ Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Properties ### Field ```ts -Field: FieldComponent; +Field: FieldComponent; ``` -Defined in: [packages/react-form/src/useForm.tsx:21](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L21) +Defined in: [packages/react-form/src/useForm.tsx:34](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L34) A React component to render form fields. With this, you can render and manage individual form fields. @@ -35,13 +51,13 @@ A React component to render form fields. With this, you can render and manage in Subscribe: (props) => ReactNode; ``` -Defined in: [packages/react-form/src/useForm.tsx:25](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L25) +Defined in: [packages/react-form/src/useForm.tsx:48](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L48) A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates. #### Type Parameters -• **TSelected** = `FormState`\<`TFormData`\> +• **TSelected** = `FormState`\<`TFormData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> #### Parameters diff --git a/docs/framework/react/reference/type-aliases/fieldcomponent.md b/docs/framework/react/reference/type-aliases/fieldcomponent.md index 00fc39ca7..cb3001163 100644 --- a/docs/framework/react/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/react/reference/type-aliases/fieldcomponent.md @@ -3,16 +3,18 @@ id: FieldComponent title: FieldComponent --- -# Type Alias: FieldComponent()\ + + +# Type Alias: FieldComponent()\ ```ts -type FieldComponent = ({ +type FieldComponent = ({ children, ...fieldOptions }) => ReactNode; ``` -Defined in: [packages/react-form/src/useField.tsx:134](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L134) +Defined in: [packages/react-form/src/useField.tsx:281](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L281) A type alias representing a field component for a specific form data type. @@ -22,6 +24,20 @@ A type alias representing a field component for a specific form data type. • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + ## Type Parameters • **TName** *extends* `DeepKeys`\<`TParentData`\> @@ -32,6 +48,20 @@ A type alias representing a field component for a specific form data type. • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### \{ @@ -39,7 +69,7 @@ A type alias representing a field component for a specific form data type. ...fieldOptions \} -`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\>, `"form"`\> ## Returns diff --git a/docs/framework/react/reference/type-aliases/reactformextendedapi.md b/docs/framework/react/reference/type-aliases/reactformextendedapi.md index ec56e7c0d..fc3e7d117 100644 --- a/docs/framework/react/reference/type-aliases/reactformextendedapi.md +++ b/docs/framework/react/reference/type-aliases/reactformextendedapi.md @@ -3,13 +3,15 @@ id: ReactFormExtendedApi title: ReactFormExtendedApi --- -# Type Alias: ReactFormExtendedApi\ + + +# Type Alias: ReactFormExtendedApi\ ```ts -type ReactFormExtendedApi = FormApi & ReactFormApi; +type ReactFormExtendedApi = FormApi & ReactFormApi; ``` -Defined in: [packages/react-form/src/useForm.tsx:34](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L34) +Defined in: [packages/react-form/src/useForm.tsx:83](https://github.com/TanStack/form/blob/main/packages/react-form/src/useForm.tsx#L83) An extended version of the `FormApi` class that includes React-specific functionalities from `ReactFormApi` @@ -18,3 +20,17 @@ An extended version of the `FormApi` class that includes React-specific function • **TFormData** • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` diff --git a/docs/framework/react/reference/type-aliases/usefield.md b/docs/framework/react/reference/type-aliases/usefield.md index 6ebd1f268..fbb751602 100644 --- a/docs/framework/react/reference/type-aliases/usefield.md +++ b/docs/framework/react/reference/type-aliases/usefield.md @@ -3,13 +3,15 @@ id: UseField title: UseField --- -# Type Alias: UseField()\ + + +# Type Alias: UseField()\ ```ts -type UseField = (opts) => FieldApi; +type UseField = (opts) => FieldApi; ``` -Defined in: [packages/react-form/src/useField.tsx:26](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L26) +Defined in: [packages/react-form/src/useField.tsx:43](https://github.com/TanStack/form/blob/main/packages/react-form/src/useField.tsx#L43) A type representing a hook for using a field in a form with the given form data type. @@ -21,6 +23,20 @@ A function that takes an optional object with a `name` property and field option • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + ## Type Parameters • **TName** *extends* `DeepKeys`\<`TParentData`\> @@ -31,12 +47,26 @@ A function that takes an optional object with a `name` property and field option • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### opts -`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\>, `"form"`\> ## Returns -`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`\> diff --git a/docs/framework/solid/guides/validation.md b/docs/framework/solid/guides/validation.md index 08c60857b..74c2c7d73 100644 --- a/docs/framework/solid/guides/validation.md +++ b/docs/framework/solid/guides/validation.md @@ -152,6 +152,32 @@ Or use the `errorMap` property to access the specific error you're looking for: ``` + +It's worth mentioning that our `errors` array and the `errorMap` matches the types returned by the validators. This means that: + +```tsx + + value < 13 ? {isOldEnough: false} : undefined, + }} +> + {(field) => ( + <> + {/* ... */} + {/* errorMap.onChange is type `{isOldEnough: false} | undefined` */} + {/* meta.errors is type `Array<{isOldEnough: false} | undefined>` */} + {!field().state.meta.errorMap['onChange']?.isOldEnough ? ( + The user is not old enough + ) : null} + + )} + +``` + + + ## Validation at field level vs at form level As shown above, each `` accepts its own validation rules via the `onChange`, `onBlur` etc... callbacks. It is also possible to define validation rules at the form level (as opposed to field by field) by passing similar callbacks to the `createForm()` hook. diff --git a/docs/framework/solid/reference/functions/createfield.md b/docs/framework/solid/reference/functions/createfield.md index 6befedc54..424370e5e 100644 --- a/docs/framework/solid/reference/functions/createfield.md +++ b/docs/framework/solid/reference/functions/createfield.md @@ -3,13 +3,15 @@ id: createField title: createField --- + + # Function: createField() ```ts -function createField(opts): () => never +function createField(opts): () => FieldApi & SolidFieldApi ``` -Defined in: [packages/solid-form/src/createField.tsx:87](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L87) +Defined in: [packages/solid-form/src/createField.tsx:237](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L237) ## Type Parameters @@ -25,11 +27,41 @@ Defined in: [packages/solid-form/src/createField.tsx:87](https://github.com/TanS • **TData** = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Parameters ### opts -() => `CreateFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +() => `CreateFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Returns @@ -37,4 +69,4 @@ Defined in: [packages/solid-form/src/createField.tsx:87](https://github.com/TanS ### Returns -`never` +`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & `SolidFieldApi`\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> diff --git a/docs/framework/solid/reference/functions/createform.md b/docs/framework/solid/reference/functions/createform.md index 4408204c0..3f57871c6 100644 --- a/docs/framework/solid/reference/functions/createform.md +++ b/docs/framework/solid/reference/functions/createform.md @@ -3,13 +3,15 @@ id: createForm title: createForm --- + + # Function: createForm() ```ts -function createForm(opts?): FormApi & SolidFormApi +function createForm(opts?): FormApi & SolidFormApi ``` -Defined in: [packages/solid-form/src/createForm.tsx:26](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L26) +Defined in: [packages/solid-form/src/createForm.tsx:112](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L112) ## Type Parameters @@ -17,12 +19,28 @@ Defined in: [packages/solid-form/src/createForm.tsx:26](https://github.com/TanSt • **TFormValidator** *extends* `undefined` \| `Validator`\<`TParentData`, `unknown`\> = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Parameters ### opts? -() => `FormOptions`\<`TParentData`, `TFormValidator`\> +() => `FormOptions`\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Returns -`FormApi`\<`TParentData`, `TFormValidator`\> & [`SolidFormApi`](../interfaces/solidformapi.md)\<`TParentData`, `TFormValidator`\> +`FormApi`\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & [`SolidFormApi`](../interfaces/solidformapi.md)\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> diff --git a/docs/framework/solid/reference/functions/field.md b/docs/framework/solid/reference/functions/field.md index 7cb6956d1..80f982927 100644 --- a/docs/framework/solid/reference/functions/field.md +++ b/docs/framework/solid/reference/functions/field.md @@ -3,13 +3,15 @@ id: Field title: Field --- + + # Function: Field() ```ts -function Field(props): Element +function Field(props): Element ``` -Defined in: [packages/solid-form/src/createField.tsx:196](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L196) +Defined in: [packages/solid-form/src/createField.tsx:483](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L483) ## Type Parameters @@ -25,11 +27,41 @@ Defined in: [packages/solid-form/src/createField.tsx:196](https://github.com/Tan • **TData** = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Parameters ### props -`object` & `FieldApiOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> & `object` +`object` & `FieldApiOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & `object` ## Returns diff --git a/docs/framework/solid/reference/functions/usestore.md b/docs/framework/solid/reference/functions/usestore.md index b1251110e..a2456113e 100644 --- a/docs/framework/solid/reference/functions/usestore.md +++ b/docs/framework/solid/reference/functions/usestore.md @@ -3,6 +3,8 @@ id: useStore title: useStore --- + + # Function: useStore() ## Call Signature @@ -11,7 +13,7 @@ title: useStore function useStore(store, selector?): Accessor ``` -Defined in: node\_modules/.pnpm/@tanstack+solid-store@0.7.0\_solid-js@1.9.3/node\_modules/@tanstack/solid-store/dist/esm/index.d.ts:8 +Defined in: node\_modules/.pnpm/@tanstack+solid-store@0.7.0\_solid-js@1.9.4/node\_modules/@tanstack/solid-store/dist/esm/index.d.ts:8 ### Type Parameters @@ -39,7 +41,7 @@ Defined in: node\_modules/.pnpm/@tanstack+solid-store@0.7.0\_solid-js@1.9.3/node function useStore(store, selector?): Accessor ``` -Defined in: node\_modules/.pnpm/@tanstack+solid-store@0.7.0\_solid-js@1.9.3/node\_modules/@tanstack/solid-store/dist/esm/index.d.ts:9 +Defined in: node\_modules/.pnpm/@tanstack+solid-store@0.7.0\_solid-js@1.9.4/node\_modules/@tanstack/solid-store/dist/esm/index.d.ts:9 ### Type Parameters diff --git a/docs/framework/solid/reference/index.md b/docs/framework/solid/reference/index.md index 704a66cb7..29000ff25 100644 --- a/docs/framework/solid/reference/index.md +++ b/docs/framework/solid/reference/index.md @@ -3,6 +3,8 @@ id: "@tanstack/solid-form" title: "@tanstack/solid-form" --- + + # @tanstack/solid-form ## Interfaces diff --git a/docs/framework/solid/reference/interfaces/solidformapi.md b/docs/framework/solid/reference/interfaces/solidformapi.md index a0ae50053..6f5caf44e 100644 --- a/docs/framework/solid/reference/interfaces/solidformapi.md +++ b/docs/framework/solid/reference/interfaces/solidformapi.md @@ -3,7 +3,9 @@ id: SolidFormApi title: SolidFormApi --- -# Interface: SolidFormApi\ + + +# Interface: SolidFormApi\ Defined in: [packages/solid-form/src/createForm.tsx:11](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L11) @@ -13,25 +15,41 @@ Defined in: [packages/solid-form/src/createForm.tsx:11](https://github.com/TanSt • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Properties ### createField ```ts -createField: CreateField; +createField: CreateField; ``` -Defined in: [packages/solid-form/src/createForm.tsx:16](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L16) +Defined in: [packages/solid-form/src/createForm.tsx:35](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L35) *** ### Field ```ts -Field: FieldComponent; +Field: FieldComponent; ``` -Defined in: [packages/solid-form/src/createForm.tsx:15](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L15) +Defined in: [packages/solid-form/src/createForm.tsx:23](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L23) *** @@ -41,11 +59,11 @@ Defined in: [packages/solid-form/src/createForm.tsx:15](https://github.com/TanSt Subscribe: (props) => Element; ``` -Defined in: [packages/solid-form/src/createForm.tsx:20](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L20) +Defined in: [packages/solid-form/src/createForm.tsx:78](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L78) #### Type Parameters -• **TSelected** = `FormState`\<`TFormData`\> +• **TSelected** = `FormState`\<`TFormData`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Parameters @@ -71,11 +89,11 @@ Defined in: [packages/solid-form/src/createForm.tsx:20](https://github.com/TanSt useStore: (selector?) => () => TSelected; ``` -Defined in: [packages/solid-form/src/createForm.tsx:17](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L17) +Defined in: [packages/solid-form/src/createForm.tsx:47](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createForm.tsx#L47) #### Type Parameters -• **TSelected** = `FormState`\<`TFormData`\> +• **TSelected** = `FormState`\<`TFormData`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Parameters diff --git a/docs/framework/solid/reference/type-aliases/createfield.md b/docs/framework/solid/reference/type-aliases/createfield.md index 3c91dcf69..69720a9ca 100644 --- a/docs/framework/solid/reference/type-aliases/createfield.md +++ b/docs/framework/solid/reference/type-aliases/createfield.md @@ -3,13 +3,15 @@ id: CreateField title: CreateField --- -# Type Alias: CreateField()\ + + +# Type Alias: CreateField()\ ```ts -type CreateField = (opts) => () => FieldApi & SolidFieldApi; +type CreateField = (opts) => () => FieldApi & SolidFieldApi; ``` -Defined in: [packages/solid-form/src/createField.tsx:29](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L29) +Defined in: [packages/solid-form/src/createField.tsx:48](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L48) ## Type Parameters @@ -17,6 +19,22 @@ Defined in: [packages/solid-form/src/createField.tsx:29](https://github.com/TanS • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Type Parameters • **TName** *extends* `DeepKeys`\<`TParentData`\> @@ -27,11 +45,25 @@ Defined in: [packages/solid-form/src/createField.tsx:29](https://github.com/TanS • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### opts -() => `object` & `Omit`\<`CreateFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +() => `object` & `Omit`\<`CreateFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>, `"form"`\> ## Returns @@ -39,4 +71,4 @@ Defined in: [packages/solid-form/src/createField.tsx:29](https://github.com/TanS ### Returns -`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> & `SolidFieldApi`\<`TParentData`, `TFormValidator`\> +`FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & `SolidFieldApi`\<`TParentData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> diff --git a/docs/framework/solid/reference/type-aliases/fieldcomponent.md b/docs/framework/solid/reference/type-aliases/fieldcomponent.md index d0464a4ea..a577234a7 100644 --- a/docs/framework/solid/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/solid/reference/type-aliases/fieldcomponent.md @@ -3,16 +3,18 @@ id: FieldComponent title: FieldComponent --- -# Type Alias: FieldComponent()\ + + +# Type Alias: FieldComponent()\ ```ts -type FieldComponent = ({ +type FieldComponent = ({ children, ...fieldOptions }) => JSXElement; ``` -Defined in: [packages/solid-form/src/createField.tsx:171](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L171) +Defined in: [packages/solid-form/src/createField.tsx:428](https://github.com/TanStack/form/blob/main/packages/solid-form/src/createField.tsx#L428) ## Type Parameters @@ -20,6 +22,22 @@ Defined in: [packages/solid-form/src/createField.tsx:171](https://github.com/Tan • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Type Parameters • **TName** *extends* `DeepKeys`\<`TParentData`\> @@ -30,6 +48,20 @@ Defined in: [packages/solid-form/src/createField.tsx:171](https://github.com/Tan • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### \{ @@ -37,7 +69,7 @@ Defined in: [packages/solid-form/src/createField.tsx:171](https://github.com/Tan ...fieldOptions \} -`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>, `"form"`\> ## Returns diff --git a/docs/framework/vue/guides/basic-concepts.md b/docs/framework/vue/guides/basic-concepts.md index 86a8a90f9..1dc101e30 100644 --- a/docs/framework/vue/guides/basic-concepts.md +++ b/docs/framework/vue/guides/basic-concepts.md @@ -12,12 +12,12 @@ You can create options for your form so that it can be shared between multiple f Example: ```ts -const formOpts = formOptions({ +const formOpts = formOptions({ defaultValues: { firstName: '', lastName: '', hobbies: [], - }, + } as Person, }) ``` @@ -38,7 +38,7 @@ const form = useForm({ You may also create a form instance without using `formOptions` by using the standalone `useForm` API: ```ts -const form = useForm({ +const form = useForm({ onSubmit: async ({ value }) => { // Do something with form data console.log(value) @@ -47,7 +47,7 @@ const form = useForm({ firstName: '', lastName: '', hobbies: [], - }, + } as Person, }) ``` diff --git a/docs/framework/vue/guides/validation.md b/docs/framework/vue/guides/validation.md index beb3f7504..c0cf8928e 100644 --- a/docs/framework/vue/guides/validation.md +++ b/docs/framework/vue/guides/validation.md @@ -143,6 +143,26 @@ Or use the `errorMap` property to access the specific error you're looking for: ``` +It's worth mentioning that our `errors` array and the `errorMap` matches the types returned by the validators. This means that: + +```vue + + + +``` + + ## Validation at field level vs at form level As shown above, each `` accepts its own validation rules via the `onChange`, `onBlur` etc... callbacks. It is also possible to define validation rules at the form level (as opposed to field by field) by passing similar callbacks to the `useForm()` function. diff --git a/docs/framework/vue/quick-start.md b/docs/framework/vue/quick-start.md index 5b3648d85..5b719ddd2 100644 --- a/docs/framework/vue/quick-start.md +++ b/docs/framework/vue/quick-start.md @@ -3,12 +3,6 @@ id: quick-start title: Quick Start --- -> There is a bug in Vue's TypeScript support that's impacting our types that you'll likely run into: -> -> https://github.com/vuejs/language-tools/issues/3782 -> -> Please give it a thumbs up, but _do not reply with comments such as "+1" or "When will this be fixed?", as such comments are unhelpful and rude_. - The bare minimum to get started with TanStack Form is to create a form and add a field. Keep in mind that this example does not include any validation or error handling... yet. ```vue diff --git a/docs/framework/vue/reference/functions/usefield.md b/docs/framework/vue/reference/functions/usefield.md index 2f06fddb5..00f2e0043 100644 --- a/docs/framework/vue/reference/functions/usefield.md +++ b/docs/framework/vue/reference/functions/usefield.md @@ -3,13 +3,15 @@ id: useField title: useField --- + + # Function: useField() ```ts -function useField(opts): object +function useField(opts): object ``` -Defined in: [packages/vue-form/src/useField.tsx:49](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L49) +Defined in: [packages/vue-form/src/useField.tsx:303](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L303) ## Type Parameters @@ -25,11 +27,41 @@ Defined in: [packages/vue-form/src/useField.tsx:49](https://github.com/TanStack/ • **TData** = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Parameters ### opts -`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Returns @@ -38,11 +70,11 @@ Defined in: [packages/vue-form/src/useField.tsx:49](https://github.com/TanStack/ ### api ```ts -readonly api: FieldApi & VueFieldApi = fieldApi; +readonly api: FieldApi & VueFieldApi = fieldApi; ``` ### state ```ts -readonly state: Readonly, FieldState>> = fieldState; +readonly state: Readonly, FieldState>> = fieldState; ``` diff --git a/docs/framework/vue/reference/functions/useform.md b/docs/framework/vue/reference/functions/useform.md index 2d67b6719..83889c30b 100644 --- a/docs/framework/vue/reference/functions/useform.md +++ b/docs/framework/vue/reference/functions/useform.md @@ -3,13 +3,15 @@ id: useForm title: useForm --- + + # Function: useForm() ```ts -function useForm(opts?): FormApi & VueFormApi +function useForm(opts?): FormApi & VueFormApi ``` -Defined in: [packages/vue-form/src/useForm.tsx:30](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L30) +Defined in: [packages/vue-form/src/useForm.tsx:190](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L190) ## Type Parameters @@ -17,12 +19,28 @@ Defined in: [packages/vue-form/src/useForm.tsx:30](https://github.com/TanStack/f • **TFormValidator** *extends* `undefined` \| `Validator`\<`TFormData`, `unknown`\> = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Parameters ### opts? -`FormOptions`\<`TFormData`, `TFormValidator`\> +`FormOptions`\<`TFormData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Returns -`FormApi`\<`TFormData`, `TFormValidator`\> & [`VueFormApi`](../interfaces/vueformapi.md)\<`TFormData`, `TFormValidator`\> +`FormApi`\<`TFormData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & [`VueFormApi`](../interfaces/vueformapi.md)\<`TFormData`, `TFormValidator`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> diff --git a/docs/framework/vue/reference/functions/usestore.md b/docs/framework/vue/reference/functions/usestore.md index 60c4f752a..e4d61b41c 100644 --- a/docs/framework/vue/reference/functions/usestore.md +++ b/docs/framework/vue/reference/functions/usestore.md @@ -3,6 +3,8 @@ id: useStore title: useStore --- + + # Function: useStore() ## Call Signature @@ -11,7 +13,7 @@ title: useStore function useStore(store, selector?): Readonly> ``` -Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.7.0\_vue@3.5.12\_typescript@5.7.2\_/node\_modules/@tanstack/vue-store/dist/esm/index.d.ts:8 +Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.7.0\_vue@3.5.13\_typescript@5.6.3\_/node\_modules/@tanstack/vue-store/dist/esm/index.d.ts:8 ### Type Parameters @@ -39,7 +41,7 @@ Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.7.0\_vue@3.5.12\_typescrip function useStore(store, selector?): Readonly> ``` -Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.7.0\_vue@3.5.12\_typescript@5.7.2\_/node\_modules/@tanstack/vue-store/dist/esm/index.d.ts:9 +Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.7.0\_vue@3.5.13\_typescript@5.6.3\_/node\_modules/@tanstack/vue-store/dist/esm/index.d.ts:9 ### Type Parameters diff --git a/docs/framework/vue/reference/index.md b/docs/framework/vue/reference/index.md index 27abe16df..0ff69a5aa 100644 --- a/docs/framework/vue/reference/index.md +++ b/docs/framework/vue/reference/index.md @@ -3,6 +3,8 @@ id: "@tanstack/vue-form" title: "@tanstack/vue-form" --- + + # @tanstack/vue-form ## Interfaces @@ -13,6 +15,7 @@ title: "@tanstack/vue-form" ## Type Aliases - [FieldComponent](type-aliases/fieldcomponent.md) +- [FieldComponentProps](type-aliases/fieldcomponentprops.md) - [UseField](type-aliases/usefield.md) ## Variables diff --git a/docs/framework/vue/reference/interfaces/vuefieldapi.md b/docs/framework/vue/reference/interfaces/vuefieldapi.md index 5b638938c..0bbf21697 100644 --- a/docs/framework/vue/reference/interfaces/vuefieldapi.md +++ b/docs/framework/vue/reference/interfaces/vuefieldapi.md @@ -3,9 +3,11 @@ id: VueFieldApi title: VueFieldApi --- -# Interface: VueFieldApi\ + -Defined in: [packages/vue-form/src/useField.tsx:8](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L8) +# Interface: VueFieldApi\ + +Defined in: [packages/vue-form/src/useField.tsx:160](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L160) ## Type Parameters @@ -13,12 +15,28 @@ Defined in: [packages/vue-form/src/useField.tsx:8](https://github.com/TanStack/f • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Properties ### Field ```ts -Field: FieldComponent; +Field: FieldComponent; ``` -Defined in: [packages/vue-form/src/useField.tsx:14](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L14) +Defined in: [packages/vue-form/src/useField.tsx:174](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L174) diff --git a/docs/framework/vue/reference/interfaces/vueformapi.md b/docs/framework/vue/reference/interfaces/vueformapi.md index 9cd097244..e110d2916 100644 --- a/docs/framework/vue/reference/interfaces/vueformapi.md +++ b/docs/framework/vue/reference/interfaces/vueformapi.md @@ -3,9 +3,11 @@ id: VueFormApi title: VueFormApi --- -# Interface: VueFormApi\ + -Defined in: [packages/vue-form/src/useForm.tsx:10](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L10) +# Interface: VueFormApi\ + +Defined in: [packages/vue-form/src/useForm.tsx:110](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L110) ## Type Parameters @@ -13,57 +15,51 @@ Defined in: [packages/vue-form/src/useForm.tsx:10](https://github.com/TanStack/f • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` -## Properties +• **TFormOnMountReturn** = `undefined` -### Field +• **TFormOnChangeReturn** = `undefined` -```ts -Field: FieldComponent; -``` +• **TFormOnChangeAsyncReturn** = `undefined` -Defined in: [packages/vue-form/src/useForm.tsx:14](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L14) +• **TFormOnBlurReturn** = `undefined` -*** +• **TFormOnBlurAsyncReturn** = `undefined` -### Subscribe() +• **TFormOnSubmitReturn** = `undefined` -```ts -Subscribe: (props, context) => any; -``` - -Defined in: [packages/vue-form/src/useForm.tsx:19](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L19) - -#### Type Parameters +• **TFormOnSubmitAsyncReturn** = `undefined` -• **TSelected** = `FormState`\<`TFormData`\> +• **TFormOnServerReturn** = `undefined` -#### Parameters +## Properties -##### props +### Field -###### selector +```ts +Field: FieldComponent; +``` -(`state`) => `TSelected` +Defined in: [packages/vue-form/src/useForm.tsx:122](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L122) -##### context +*** -`SetupContext`\<`EmitsOptions`, `SlotsType`\<\{ - `default`: `FormState`\<`TFormData`\>; - \}\>\> +### Subscribe -#### Returns +```ts +Subscribe: SubscribeComponent; +``` -`any` +Defined in: [packages/vue-form/src/useForm.tsx:177](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L177) *** ### useField ```ts -useField: UseField; +useField: UseField; ``` -Defined in: [packages/vue-form/src/useForm.tsx:15](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L15) +Defined in: [packages/vue-form/src/useForm.tsx:134](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L134) *** @@ -73,11 +69,11 @@ Defined in: [packages/vue-form/src/useForm.tsx:15](https://github.com/TanStack/f useStore: (selector?) => Readonly>; ``` -Defined in: [packages/vue-form/src/useForm.tsx:16](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L16) +Defined in: [packages/vue-form/src/useForm.tsx:146](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx#L146) #### Type Parameters -• **TSelected** = `FormState`\<`TFormData`\> +• **TSelected** = `FormState`\<`TFormData`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Parameters diff --git a/docs/framework/vue/reference/type-aliases/fieldcomponent.md b/docs/framework/vue/reference/type-aliases/fieldcomponent.md index 15179546d..58cca2a70 100644 --- a/docs/framework/vue/reference/type-aliases/fieldcomponent.md +++ b/docs/framework/vue/reference/type-aliases/fieldcomponent.md @@ -3,13 +3,20 @@ id: FieldComponent title: FieldComponent --- -# Type Alias: FieldComponent()\ + + +# Type Alias: FieldComponent()\ ```ts -type FieldComponent = (fieldOptions, context) => any; +type FieldComponent = (props) => CreateComponentPublicInstanceWithMixins, "form">, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, SlotsType<{ + default: { + field: FieldApi; + state: FieldApi["state"]; + }; +}>>; ``` -Defined in: [packages/vue-form/src/useField.tsx:117](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L117) +Defined in: [packages/vue-form/src/useField.tsx:17](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L17) ## Type Parameters @@ -17,31 +24,33 @@ Defined in: [packages/vue-form/src/useField.tsx:117](https://github.com/TanStack • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` -## Type Parameters +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` -• **TName** *extends* `DeepKeys`\<`TParentData`\> +• **TFormOnBlurAsyncReturn** = `undefined` -• **TFieldValidator** *extends* - \| `Validator`\<`DeepValue`\<`TParentData`, `TName`\>, `unknown`\> - \| `undefined` = `undefined` +• **TFormOnSubmitReturn** = `undefined` -• **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` ## Parameters -### fieldOptions +### props -`Omit`\<`FieldComponentProps`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +`Omit`\<[`FieldComponentProps`](fieldcomponentprops.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>, `"form"`\> & `EmitsToProps`\<`EmitsOptions`\> & `PublicProps` -### context +## Returns -`SetupContext`\<\{\}, `SlotsType`\<\{ +`CreateComponentPublicInstanceWithMixins`\<`Omit`\<[`FieldComponentProps`](fieldcomponentprops.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>, `"form"`\>, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, `SlotsType`\<\{ `default`: \{ - `field`: `FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>; - `state`: `FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>\[`"state"`\]; + `field`: `FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>; + `state`: `FieldApi`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>\[`"state"`\]; \}; \}\>\> - -## Returns - -`any` diff --git a/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md b/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md new file mode 100644 index 000000000..7e54c8def --- /dev/null +++ b/docs/framework/vue/reference/type-aliases/fieldcomponentprops.md @@ -0,0 +1,58 @@ +--- +id: FieldComponentProps +title: FieldComponentProps +--- + + + +# Type Alias: FieldComponentProps\ + +```ts +type FieldComponentProps = UseFieldOptions; +``` + +Defined in: [packages/vue-form/src/useField.tsx:400](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L400) + +## Type Parameters + +• **TParentData** + +• **TName** *extends* `DeepKeys`\<`TParentData`\> + +• **TFieldValidator** *extends* + \| `Validator`\<`DeepValue`\<`TParentData`, `TName`\>, `unknown`\> + \| `undefined` = `undefined` + +• **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` + +• **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` diff --git a/docs/framework/vue/reference/type-aliases/usefield.md b/docs/framework/vue/reference/type-aliases/usefield.md index 5fb33846e..68ed46b3c 100644 --- a/docs/framework/vue/reference/type-aliases/usefield.md +++ b/docs/framework/vue/reference/type-aliases/usefield.md @@ -3,13 +3,15 @@ id: UseField title: UseField --- -# Type Alias: UseField()\ + + +# Type Alias: UseField()\ ```ts -type UseField = (opts) => object; +type UseField = (opts) => object; ``` -Defined in: [packages/vue-form/src/useField.tsx:17](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L17) +Defined in: [packages/vue-form/src/useField.tsx:188](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L188) ## Type Parameters @@ -17,6 +19,22 @@ Defined in: [packages/vue-form/src/useField.tsx:17](https://github.com/TanStack/ • **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined` +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Type Parameters • **TName** *extends* `DeepKeys`\<`TParentData`\> @@ -27,11 +45,25 @@ Defined in: [packages/vue-form/src/useField.tsx:17](https://github.com/TanStack/ • **TData** *extends* `DeepValue`\<`TParentData`, `TName`\> = `DeepValue`\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Parameters ### opts -`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\>, `"form"`\> +`Omit`\<`UseFieldOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\>, `"form"`\> ## Returns @@ -40,11 +72,11 @@ Defined in: [packages/vue-form/src/useField.tsx:17](https://github.com/TanStack/ ### api ```ts -api: FieldApi & VueFieldApi; +api: FieldApi & VueFieldApi; ``` ### state ```ts -state: Readonly["state"]>>; +state: Readonly["state"]>>; ``` diff --git a/docs/framework/vue/reference/variables/field.md b/docs/framework/vue/reference/variables/field.md index 8b9c3092d..321506be8 100644 --- a/docs/framework/vue/reference/variables/field.md +++ b/docs/framework/vue/reference/variables/field.md @@ -3,20 +3,22 @@ id: Field title: Field --- + + # Variable: Field() ```ts -const Field: (props) => CreateComponentPublicInstanceWithMixins & object & {} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, {}, {}, {}, string, {}, any, ComponentProvideOptions, OptionTypesType<{}, {}, {}, {}, {}, {}>, object & FieldApiOptions & { mode?: "value" | ... 1 more ... | undefined; } & ({ ...; } | { ...; }), {}, {}, {}, {}, {}>; +const Field: (props) => CreateComponentPublicInstanceWithMixins & object & {} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, PublicProps, {}, false, {}, {}, {}, {}, string, {}, any, ComponentProvideOptions, OptionTypesType<{}, {}, {}, {}, {}, {}>, object & FieldApiOptions & { ...; } & ({ ...; } | { ...; }), {}, {}, {}, {}, {}>; ``` -Defined in: [packages/vue-form/src/useField.tsx:162](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L162) +Defined in: [packages/vue-form/src/useField.tsx:448](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx#L448) ## Parameters ### props -FieldApiOptions\ & \{ mode?: "value" \| ... 1 more ... \| undefined; \} & (\{ ...; \} \| \{ ...; \}) & `VNodeProps` & `AllowedComponentProps` & `ComponentCustomProps` +FieldApiOptions\ & \{ ...; \} & (\{ ...; \} \| \{ ...; \}) & `VNodeProps` & `AllowedComponentProps` & `ComponentCustomProps` ## Returns -`CreateComponentPublicInstanceWithMixins`\<`FieldApiOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> & `object` & \{\} \| \{\}, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, \{\}, \{\}, \{\}, `string`, \{\}, `any`, `ComponentProvideOptions`, `OptionTypesType`\<\{\}, \{\}, \{\}, \{\}, \{\}, \{\}\>, `object` & FieldApiOptions\ & \{ mode?: "value" \| ... 1 more ... \| undefined; \} & (\{ ...; \} \| \{ ...; \}), \{\}, \{\}, \{\}, \{\}, \{\}\> +`CreateComponentPublicInstanceWithMixins`\<`FieldApiOptions`\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> & `object` & \{\} \| \{\}, \{\}, \{\}, \{\}, \{\}, `ComponentOptionsMixin`, `ComponentOptionsMixin`, `EmitsOptions`, `PublicProps`, \{\}, `false`, \{\}, \{\}, \{\}, \{\}, `string`, \{\}, `any`, `ComponentProvideOptions`, `OptionTypesType`\<\{\}, \{\}, \{\}, \{\}, \{\}, \{\}\>, `object` & FieldApiOptions\ & \{ ...; \} & (\{ ...; \} \| \{ ...; \}), \{\}, \{\}, \{\}, \{\}, \{\}\> diff --git a/docs/overview.md b/docs/overview.md index a0506af9d..a5620be86 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -33,9 +33,9 @@ In the example below, you can see TanStack Form in action with the React framewo import * as React from 'react' import { createRoot } from 'react-dom/client' import { useForm } from '@tanstack/react-form' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/docs/reference/classes/fieldapi.md b/docs/reference/classes/fieldapi.md index 5821b91af..6e5231f87 100644 --- a/docs/reference/classes/fieldapi.md +++ b/docs/reference/classes/fieldapi.md @@ -3,9 +3,11 @@ id: FieldApi title: FieldApi --- -# Class: FieldApi\ + -Defined in: [packages/form-core/src/FieldApi.ts:427](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L427) +# Class: FieldApi\ + +Defined in: [packages/form-core/src/FieldApi.ts:685](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L685) A class representing the API for managing a form field. @@ -29,15 +31,45 @@ the `new FieldApi` constructor. • **TData** *extends* [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> = [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Constructors ### new FieldApi() ```ts -new FieldApi(opts): FieldApi +new FieldApi(opts): FieldApi ``` -Defined in: [packages/form-core/src/FieldApi.ts:477](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L477) +Defined in: [packages/form-core/src/FieldApi.ts:790](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L790) Initializes a new `FieldApi` instance. @@ -45,21 +77,21 @@ Initializes a new `FieldApi` instance. ##### opts -[`FieldApiOptions`](../interfaces/fieldapioptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +[`FieldApiOptions`](../interfaces/fieldapioptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Returns -[`FieldApi`](fieldapi.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +[`FieldApi`](fieldapi.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> ## Properties ### form ```ts -form: FormApi; +form: FormApi; ``` -Defined in: [packages/form-core/src/FieldApi.ts:441](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L441) +Defined in: [packages/form-core/src/FieldApi.ts:714](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L714) A reference to the form API instance. @@ -71,7 +103,7 @@ A reference to the form API instance. name: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never; ``` -Defined in: [packages/form-core/src/FieldApi.ts:451](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L451) +Defined in: [packages/form-core/src/FieldApi.ts:739](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L739) The field name. @@ -80,10 +112,10 @@ The field name. ### options ```ts -options: FieldApiOptions; +options: FieldApiOptions; ``` -Defined in: [packages/form-core/src/FieldApi.ts:455](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L455) +Defined in: [packages/form-core/src/FieldApi.ts:743](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L743) The field options. @@ -92,10 +124,10 @@ The field options. ### store ```ts -store: Derived>; +store: Derived>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:465](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L465) +Defined in: [packages/form-core/src/FieldApi.ts:767](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L767) The field state store. @@ -107,7 +139,7 @@ The field state store. timeoutIds: Record; ``` -Defined in: [packages/form-core/src/FieldApi.ts:472](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L472) +Defined in: [packages/form-core/src/FieldApi.ts:785](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L785) ## Accessors @@ -116,16 +148,16 @@ Defined in: [packages/form-core/src/FieldApi.ts:472](https://github.com/TanStack #### Get Signature ```ts -get state(): FieldState +get state(): FieldState ``` -Defined in: [packages/form-core/src/FieldApi.ts:469](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L469) +Defined in: [packages/form-core/src/FieldApi.ts:782](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L782) The current field state. ##### Returns -[`FieldState`](../type-aliases/fieldstate.md)\<`TData`\> +[`FieldState`](../type-aliases/fieldstate.md)\<`TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ## Methods @@ -135,7 +167,7 @@ The current field state. getInfo(): FieldInfo ``` -Defined in: [packages/form-core/src/FieldApi.ts:673](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L673) +Defined in: [packages/form-core/src/FieldApi.ts:1040](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1040) Gets the field information object. @@ -148,14 +180,14 @@ Gets the field information object. ### getMeta() ```ts -getMeta(): FieldMeta +getMeta(): FieldMeta ``` -Defined in: [packages/form-core/src/FieldApi.ts:662](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L662) +Defined in: [packages/form-core/src/FieldApi.ts:1018](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1018) #### Returns -[`FieldMeta`](../type-aliases/fieldmeta.md) +[`FieldMeta`](../type-aliases/fieldmeta.md)\<`TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> *** @@ -165,7 +197,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:662](https://github.com/TanStack getValue(): TData ``` -Defined in: [packages/form-core/src/FieldApi.ts:644](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L644) +Defined in: [packages/form-core/src/FieldApi.ts:1000](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1000) Gets the current field value. @@ -185,7 +217,7 @@ Use `field.state.value` instead. handleBlur(): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1025](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1025) +Defined in: [packages/form-core/src/FieldApi.ts:1447](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1447) Handles the blur event. @@ -201,7 +233,7 @@ Handles the blur event. handleChange(updater): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1018](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1018) +Defined in: [packages/form-core/src/FieldApi.ts:1440](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1440) Handles the change event. @@ -226,7 +258,7 @@ insertValue( opts?): Promise ``` -Defined in: [packages/form-core/src/FieldApi.ts:686](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L686) +Defined in: [packages/form-core/src/FieldApi.ts:1053](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1053) Inserts a value at the specified index, shifting the subsequent values to the right. @@ -256,7 +288,7 @@ Inserts a value at the specified index, shifting the subsequent values to the ri mount(): () => void ``` -Defined in: [packages/form-core/src/FieldApi.ts:567](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L567) +Defined in: [packages/form-core/src/FieldApi.ts:905](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L905) Mounts the field instance to the form. @@ -279,7 +311,7 @@ moveValue( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:716](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L716) +Defined in: [packages/form-core/src/FieldApi.ts:1083](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1083) Moves the value at the first specified index to the second specified index. @@ -309,7 +341,7 @@ Moves the value at the first specified index to the second specified index. pushValue(value, opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:678](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L678) +Defined in: [packages/form-core/src/FieldApi.ts:1045](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1045) Pushes a new value to the field. @@ -335,7 +367,7 @@ Pushes a new value to the field. removeValue(index, opts?): Promise ``` -Defined in: [packages/form-core/src/FieldApi.ts:704](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L704) +Defined in: [packages/form-core/src/FieldApi.ts:1071](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1071) Removes a value at the specified index. @@ -364,7 +396,7 @@ replaceValue( opts?): Promise ``` -Defined in: [packages/form-core/src/FieldApi.ts:695](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L695) +Defined in: [packages/form-core/src/FieldApi.ts:1062](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1062) Replaces a value at the specified index. @@ -394,7 +426,7 @@ Replaces a value at the specified index. setErrorMap(errorMap): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:1045](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1045) +Defined in: [packages/form-core/src/FieldApi.ts:1467](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1467) Updates the field's errorMap @@ -416,7 +448,7 @@ Updates the field's errorMap setMeta(updater): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:667](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L667) +Defined in: [packages/form-core/src/FieldApi.ts:1023](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1023) Sets the field metadata. @@ -424,7 +456,7 @@ Sets the field metadata. ##### updater -[`Updater`](../type-aliases/updater.md)\<[`FieldMeta`](../type-aliases/fieldmeta.md)\> +[`Updater`](../type-aliases/updater.md)\<[`FieldMeta`](../type-aliases/fieldmeta.md)\<`TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\>\> #### Returns @@ -438,7 +470,7 @@ Sets the field metadata. setValue(updater, options?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:651](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L651) +Defined in: [packages/form-core/src/FieldApi.ts:1007](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1007) Sets the field value and run the `change` validator. @@ -467,7 +499,7 @@ swapValues( opts?): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:710](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L710) +Defined in: [packages/form-core/src/FieldApi.ts:1077](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1077) Swaps the values at the specified indices. @@ -497,7 +529,7 @@ Swaps the values at the specified indices. update(opts): void ``` -Defined in: [packages/form-core/src/FieldApi.ts:606](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L606) +Defined in: [packages/form-core/src/FieldApi.ts:947](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L947) Updates the field instance with new options. @@ -505,7 +537,7 @@ Updates the field instance with new options. ##### opts -[`FieldApiOptions`](../interfaces/fieldapioptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +[`FieldApiOptions`](../interfaces/fieldapioptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TFormOnMountReturn`, `TFormOnChangeReturn`, `TFormOnChangeAsyncReturn`, `TFormOnBlurReturn`, `TFormOnBlurAsyncReturn`, `TFormOnSubmitReturn`, `TFormOnSubmitAsyncReturn`, `TFormOnServerReturn`\> #### Returns @@ -516,12 +548,10 @@ Updates the field instance with new options. ### validate() ```ts -validate(cause): - | ValidationError[] -| Promise +validate(cause): unknown[] | Promise ``` -Defined in: [packages/form-core/src/FieldApi.ts:990](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L990) +Defined in: [packages/form-core/src/FieldApi.ts:1412](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1412) Validates the field value. @@ -533,5 +563,4 @@ Validates the field value. #### Returns - \| [`ValidationError`](../type-aliases/validationerror.md)[] - \| `Promise`\<[`ValidationError`](../type-aliases/validationerror.md)[]\> +`unknown`[] \| `Promise`\<`unknown`[]\> diff --git a/docs/reference/classes/formapi.md b/docs/reference/classes/formapi.md index e242bf9df..d049b901c 100644 --- a/docs/reference/classes/formapi.md +++ b/docs/reference/classes/formapi.md @@ -3,9 +3,11 @@ id: FormApi title: FormApi --- -# Class: FormApi\ + -Defined in: [packages/form-core/src/FormApi.ts:360](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L360) +# Class: FormApi\ + +Defined in: [packages/form-core/src/FormApi.ts:634](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L634) A class representing the Form API. It handles the logic and interactions with the form state. @@ -19,15 +21,31 @@ However, if you need to create a new instance manually, you can do so by calling • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + ## Constructors ### new FormApi() ```ts -new FormApi(opts?): FormApi +new FormApi(opts?): FormApi ``` -Defined in: [packages/form-core/src/FormApi.ts:389](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L389) +Defined in: [packages/form-core/src/FormApi.ts:706](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L706) Constructs a new `FormApi` instance with the given form options. @@ -35,21 +53,21 @@ Constructs a new `FormApi` instance with the given form options. ##### opts? -[`FormOptions`](../interfaces/formoptions.md)\<`TFormData`, `TFormValidator`\> +[`FormOptions`](../interfaces/formoptions.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> #### Returns -[`FormApi`](formapi.md)\<`TFormData`, `TFormValidator`\> +[`FormApi`](formapi.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ## Properties ### baseStore ```ts -baseStore: Store, (cb) => BaseFormState>; +baseStore: Store, (cb) => BaseFormState>; ``` -Defined in: [packages/form-core/src/FormApi.ts:368](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L368) +Defined in: [packages/form-core/src/FormApi.ts:661](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L661) *** @@ -59,7 +77,7 @@ Defined in: [packages/form-core/src/FormApi.ts:368](https://github.com/TanStack/ fieldInfo: Record ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TFormData extends any[] ? PrefixArrayAccessor, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor, []> : TFormData extends string | number | bigint | boolean ? "" : never, FieldInfo>; ``` -Defined in: [packages/form-core/src/FormApi.ts:374](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L374) +Defined in: [packages/form-core/src/FormApi.ts:691](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L691) A record of field information for each field in the form. @@ -71,17 +89,17 @@ A record of field information for each field in the form. fieldMetaDerived: Derived ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TFormData extends any[] ? PrefixArrayAccessor, [any]> : TFormData extends Date ? never : TFormData extends object ? PrefixObjectAccessor, []> : TFormData extends string | number | bigint | boolean ? "" : never, FieldMeta>>; ``` -Defined in: [packages/form-core/src/FormApi.ts:369](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L369) +Defined in: [packages/form-core/src/FormApi.ts:674](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L674) *** ### options ```ts -options: FormOptions = {}; +options: FormOptions = {}; ``` -Defined in: [packages/form-core/src/FormApi.ts:367](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L367) +Defined in: [packages/form-core/src/FormApi.ts:649](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L649) The options for the form. @@ -90,10 +108,10 @@ The options for the form. ### store ```ts -store: Derived>; +store: Derived>; ``` -Defined in: [packages/form-core/src/FormApi.ts:370](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L370) +Defined in: [packages/form-core/src/FormApi.ts:675](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L675) ## Accessors @@ -102,14 +120,14 @@ Defined in: [packages/form-core/src/FormApi.ts:370](https://github.com/TanStack/ #### Get Signature ```ts -get state(): FormState +get state(): FormState ``` -Defined in: [packages/form-core/src/FormApi.ts:377](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L377) +Defined in: [packages/form-core/src/FormApi.ts:694](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L694) ##### Returns -[`FormState`](../type-aliases/formstate.md)\<`TFormData`\> +[`FormState`](../type-aliases/formstate.md)\<`TFormData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ## Methods @@ -119,7 +137,7 @@ Defined in: [packages/form-core/src/FormApi.ts:377](https://github.com/TanStack/ deleteField(field): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1194](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1194) +Defined in: [packages/form-core/src/FormApi.ts:1632](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1632) #### Type Parameters @@ -143,7 +161,7 @@ Defined in: [packages/form-core/src/FormApi.ts:1194](https://github.com/TanStack getFieldInfo(field): FieldInfo ``` -Defined in: [packages/form-core/src/FormApi.ts:1103](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1103) +Defined in: [packages/form-core/src/FormApi.ts:1541](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1541) Gets the field info of the specified field. @@ -169,7 +187,7 @@ Gets the field info of the specified field. getFieldMeta(field): undefined | FieldMeta ``` -Defined in: [packages/form-core/src/FormApi.ts:1094](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1094) +Defined in: [packages/form-core/src/FormApi.ts:1532](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1532) Gets the metadata of the specified field. @@ -195,7 +213,7 @@ Gets the metadata of the specified field. getFieldValue(field): DeepValue> ``` -Defined in: [packages/form-core/src/FormApi.ts:1087](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1087) +Defined in: [packages/form-core/src/FormApi.ts:1525](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1525) Gets the value of the specified field. @@ -221,7 +239,7 @@ Gets the value of the specified field. handleSubmit(): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:1028](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1028) +Defined in: [packages/form-core/src/FormApi.ts:1466](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1466) Handles the form submission, performs validation, and calls the appropriate onSubmit or onInvalidSubmit callbacks. @@ -241,7 +259,7 @@ insertFieldValue( opts?): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:1226](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1226) +Defined in: [packages/form-core/src/FormApi.ts:1664](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1664) Inserts a value into an array field at the specified index, shifting the subsequent values to the right. @@ -279,7 +297,7 @@ Inserts a value into an array field at the specified index, shifting the subsequ mount(): () => void ``` -Defined in: [packages/form-core/src/FormApi.ts:607](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L607) +Defined in: [packages/form-core/src/FormApi.ts:974](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L974) #### Returns @@ -301,7 +319,7 @@ moveFieldValues( opts?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1344](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1344) +Defined in: [packages/form-core/src/FormApi.ts:1782](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1782) Moves the value at the first specified index to the second specified index within an array field. @@ -342,7 +360,7 @@ pushFieldValue( opts?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1208](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1208) +Defined in: [packages/form-core/src/FormApi.ts:1646](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1646) Pushes a value into an array field. @@ -379,7 +397,7 @@ removeFieldValue( opts?): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:1279](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1279) +Defined in: [packages/form-core/src/FormApi.ts:1717](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1717) Removes a value from an array field at the specified index. @@ -417,7 +435,7 @@ replaceFieldValue( opts?): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:1253](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1253) +Defined in: [packages/form-core/src/FormApi.ts:1691](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1691) Replaces a value into an array field at the specified index. @@ -455,7 +473,7 @@ Replaces a value into an array field at the specified index. reset(values?, opts?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:668](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L668) +Defined in: [packages/form-core/src/FormApi.ts:1048](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1048) Resets the form state to the default values. If values are provided, the form will be reset to those values instead and the default values will be updated. @@ -488,7 +506,7 @@ Optional options to control the reset behavior. resetFieldMeta(fieldMeta): Record ``` -Defined in: [packages/form-core/src/FormApi.ts:1140](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1140) +Defined in: [packages/form-core/src/FormApi.ts:1578](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1578) #### Type Parameters @@ -512,7 +530,7 @@ Defined in: [packages/form-core/src/FormApi.ts:1140](https://github.com/TanStack setErrorMap(errorMap): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1368](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1368) +Defined in: [packages/form-core/src/FormApi.ts:1806](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1806) Updates the form's errorMap @@ -520,7 +538,7 @@ Updates the form's errorMap ##### errorMap -`ValidationErrorMap` +`ValidationErrorMap`\<`TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> #### Returns @@ -534,7 +552,7 @@ Updates the form's errorMap setFieldMeta(field, updater): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1122](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1122) +Defined in: [packages/form-core/src/FormApi.ts:1560](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1560) Updates the metadata of the specified field. @@ -550,7 +568,7 @@ Updates the metadata of the specified field. ##### updater -[`Updater`](../type-aliases/updater.md)\<[`FieldMeta`](../type-aliases/fieldmeta.md)\> +[`Updater`](../type-aliases/updater.md)\<[`FieldMeta`](../type-aliases/fieldmeta.md)\<`any`, `any`, `any`, `any`, `any`, `any`, `any`\>\> #### Returns @@ -567,7 +585,7 @@ setFieldValue( opts?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1164](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1164) +Defined in: [packages/form-core/src/FormApi.ts:1602](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1602) Sets the value of the specified field and optionally updates the touched state. @@ -605,7 +623,7 @@ swapFieldValues( opts?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:1318](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1318) +Defined in: [packages/form-core/src/FormApi.ts:1756](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1756) Swaps the values at the specified indices within an array field. @@ -643,7 +661,7 @@ Swaps the values at the specified indices within an array field. update(options?): void ``` -Defined in: [packages/form-core/src/FormApi.ts:624](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L624) +Defined in: [packages/form-core/src/FormApi.ts:991](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L991) Updates the form options and form state. @@ -651,7 +669,7 @@ Updates the form options and form state. ##### options? -[`FormOptions`](../interfaces/formoptions.md)\<`TFormData`, `TFormValidator`\> +[`FormOptions`](../interfaces/formoptions.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> #### Returns @@ -662,10 +680,10 @@ Updates the form options and form state. ### validateAllFields() ```ts -validateAllFields(cause): Promise +validateAllFields(cause): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:694](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L694) +Defined in: [packages/form-core/src/FormApi.ts:1074](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1074) Validates form and all fields in using the correct handlers for a given validation cause. @@ -677,7 +695,7 @@ Validates form and all fields in using the correct handlers for a given validati #### Returns -`Promise`\<[`ValidationError`](../type-aliases/validationerror.md)[]\> +`Promise`\<`unknown`[]\> *** @@ -687,10 +705,10 @@ Validates form and all fields in using the correct handlers for a given validati validateArrayFieldsStartingFrom( field, index, -cause): Promise +cause): Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:722](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L722) +Defined in: [packages/form-core/src/FormApi.ts:1102](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1102) Validates the children of a specified array in the form starting from a given index until the end using the correct handlers for a given validation type. @@ -714,19 +732,17 @@ Validates the children of a specified array in the form starting from a given in #### Returns -`Promise`\<[`ValidationError`](../type-aliases/validationerror.md)[]\> +`Promise`\<`unknown`[]\> *** ### validateField() ```ts -validateField(field, cause): - | ValidationError[] -| Promise +validateField(field, cause): unknown[] | Promise ``` -Defined in: [packages/form-core/src/FormApi.ts:761](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L761) +Defined in: [packages/form-core/src/FormApi.ts:1141](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1141) Validates a specified field in the form using the correct handlers for a given validation type. @@ -746,5 +762,4 @@ Validates a specified field in the form using the correct handlers for a given v #### Returns - \| [`ValidationError`](../type-aliases/validationerror.md)[] - \| `Promise`\<[`ValidationError`](../type-aliases/validationerror.md)[]\> +`unknown`[] \| `Promise`\<`unknown`[]\> diff --git a/docs/reference/functions/formoptions.md b/docs/reference/functions/formoptions.md index 9b3ff5ea1..4dbbf2ac4 100644 --- a/docs/reference/functions/formoptions.md +++ b/docs/reference/functions/formoptions.md @@ -3,6 +3,8 @@ id: formOptions title: formOptions --- + + # Function: formOptions() ```ts diff --git a/docs/reference/functions/isformvalidationerror.md b/docs/reference/functions/isformvalidationerror.md new file mode 100644 index 000000000..e919b7be8 --- /dev/null +++ b/docs/reference/functions/isformvalidationerror.md @@ -0,0 +1,24 @@ +--- +id: isFormValidationError +title: isFormValidationError +--- + + + +# Function: isFormValidationError() + +```ts +function isFormValidationError(error): error is SpecialFormValidationError +``` + +Defined in: [packages/form-core/src/utils.ts:328](https://github.com/TanStack/form/blob/main/packages/form-core/src/utils.ts#L328) + +## Parameters + +### error + +`unknown` + +## Returns + +`error is SpecialFormValidationError` diff --git a/docs/reference/functions/isstandardschemavalidator.md b/docs/reference/functions/isstandardschemavalidator.md index b3f4a6001..3d58eeebd 100644 --- a/docs/reference/functions/isstandardschemavalidator.md +++ b/docs/reference/functions/isstandardschemavalidator.md @@ -3,6 +3,8 @@ id: isStandardSchemaValidator title: isStandardSchemaValidator --- + + # Function: isStandardSchemaValidator() ```ts diff --git a/docs/reference/functions/mergeform.md b/docs/reference/functions/mergeform.md index 103beee34..08aedcfd4 100644 --- a/docs/reference/functions/mergeform.md +++ b/docs/reference/functions/mergeform.md @@ -3,10 +3,12 @@ id: mergeForm title: mergeForm --- + + # Function: mergeForm() ```ts -function mergeForm(baseForm, state): FormApi, NoInfer> +function mergeForm(baseForm, state): FormApi, NoInfer, any, any, any, any, any, any, any, any> ``` Defined in: [packages/form-core/src/mergeForm.ts:36](https://github.com/TanStack/form/blob/main/packages/form-core/src/mergeForm.ts#L36) @@ -21,12 +23,12 @@ Defined in: [packages/form-core/src/mergeForm.ts:36](https://github.com/TanStack ### baseForm -[`FormApi`](../classes/formapi.md)\<`NoInfer`\<`TFormData`\>, `NoInfer`\<`TFormValidator`\>\> +[`FormApi`](../classes/formapi.md)\<`NoInfer`\<`TFormData`\>, `NoInfer`\<`TFormValidator`\>, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\> ### state -`Partial`\<[`FormState`](../type-aliases/formstate.md)\<`TFormData`\>\> +`Partial`\<[`FormState`](../type-aliases/formstate.md)\<`TFormData`, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\>\> ## Returns -[`FormApi`](../classes/formapi.md)\<`NoInfer`\<`TFormData`\>, `NoInfer`\<`TFormValidator`\>\> +[`FormApi`](../classes/formapi.md)\<`NoInfer`\<`TFormData`\>, `NoInfer`\<`TFormValidator`\>, `any`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\> diff --git a/docs/reference/functions/standardschemavalidator.md b/docs/reference/functions/standardschemavalidator.md index 22c05433c..f1798cf0e 100644 --- a/docs/reference/functions/standardschemavalidator.md +++ b/docs/reference/functions/standardschemavalidator.md @@ -3,6 +3,8 @@ id: standardSchemaValidator title: standardSchemaValidator --- + + # Function: standardSchemaValidator() ```ts diff --git a/docs/reference/index.md b/docs/reference/index.md index 6221bdca0..41a002359 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -3,6 +3,8 @@ id: "@tanstack/form-core" title: "@tanstack/form-core" --- + + # @tanstack/form-core ## Classes @@ -21,6 +23,8 @@ title: "@tanstack/form-core" ## Type Aliases +- [AnyFieldApi](type-aliases/anyfieldapi.md) +- [AnyFormApi](type-aliases/anyformapi.md) - [BaseFormState](type-aliases/baseformstate.md) - [DeepKeys](type-aliases/deepkeys.md) - [DeepValue](type-aliases/deepvalue.md) @@ -33,6 +37,7 @@ title: "@tanstack/form-core" - [FieldState](type-aliases/fieldstate.md) - [FormState](type-aliases/formstate.md) - [FormValidateFn](type-aliases/formvalidatefn.md) +- [FormValidationError](type-aliases/formvalidationerror.md) - [FormValidator](type-aliases/formvalidator.md) - [StandardSchemaV1](type-aliases/standardschemav1.md) - [Updater](type-aliases/updater.md) @@ -44,6 +49,7 @@ title: "@tanstack/form-core" ## Functions - [formOptions](functions/formoptions.md) +- [isFormValidationError](functions/isformvalidationerror.md) - [isStandardSchemaValidator](functions/isstandardschemavalidator.md) - [mergeForm](functions/mergeform.md) - [standardSchemaValidator](functions/standardschemavalidator.md) diff --git a/docs/reference/interfaces/fieldapioptions.md b/docs/reference/interfaces/fieldapioptions.md index 842ab2292..f901e7486 100644 --- a/docs/reference/interfaces/fieldapioptions.md +++ b/docs/reference/interfaces/fieldapioptions.md @@ -3,15 +3,17 @@ id: FieldApiOptions title: FieldApiOptions --- -# Interface: FieldApiOptions\ + -Defined in: [packages/form-core/src/FieldApi.ts:345](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L345) +# Interface: FieldApiOptions\ + +Defined in: [packages/form-core/src/FieldApi.ts:468](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L468) An object type representing the required options for the FieldApi class. ## Extends -- [`FieldOptions`](fieldoptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`\> +- [`FieldOptions`](fieldoptions.md)\<`TParentData`, `TName`, `TFieldValidator`, `TFormValidator`, `TData`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`\> ## Type Parameters @@ -27,6 +29,36 @@ An object type representing the required options for the FieldApi class. • **TData** *extends* [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> = [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TFormOnMountReturn** = `undefined` + +• **TFormOnChangeReturn** = `undefined` + +• **TFormOnChangeAsyncReturn** = `undefined` + +• **TFormOnBlurReturn** = `undefined` + +• **TFormOnBlurAsyncReturn** = `undefined` + +• **TFormOnSubmitReturn** = `undefined` + +• **TFormOnSubmitAsyncReturn** = `undefined` + +• **TFormOnServerReturn** = `undefined` + ## Properties ### asyncAlways? @@ -35,7 +67,7 @@ An object type representing the required options for the FieldApi class. optional asyncAlways: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:311](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L311) +Defined in: [packages/form-core/src/FieldApi.ts:427](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L427) If `true`, always run async validation, even if there are errors emitted during synchronous validation. @@ -51,7 +83,7 @@ If `true`, always run async validation, even if there are errors emitted during optional asyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:307](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L307) +Defined in: [packages/form-core/src/FieldApi.ts:423](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L423) The default time to debounce async validation if there is not a more specific debounce time passed. @@ -64,10 +96,10 @@ The default time to debounce async validation if there is not a more specific de ### defaultMeta? ```ts -optional defaultMeta: Partial; +optional defaultMeta: Partial>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:329](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L329) +Defined in: [packages/form-core/src/FieldApi.ts:452](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L452) An optional object with default metadata for the field. @@ -83,7 +115,7 @@ An optional object with default metadata for the field. optional defaultValue: NoInfer; ``` -Defined in: [packages/form-core/src/FieldApi.ts:303](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L303) +Defined in: [packages/form-core/src/FieldApi.ts:419](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L419) An optional default value for the field. @@ -96,10 +128,10 @@ An optional default value for the field. ### form ```ts -form: FormApi; +form: FormApi; ``` -Defined in: [packages/form-core/src/FieldApi.ts:362](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L362) +Defined in: [packages/form-core/src/FieldApi.ts:507](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L507) *** @@ -109,7 +141,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:362](https://github.com/TanStack optional listeners: FieldListeners; ``` -Defined in: [packages/form-core/src/FieldApi.ts:333](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L333) +Defined in: [packages/form-core/src/FieldApi.ts:456](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L456) A list of listeners which attach to the corresponding events @@ -125,7 +157,7 @@ A list of listeners which attach to the corresponding events name: TName; ``` -Defined in: [packages/form-core/src/FieldApi.ts:299](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L299) +Defined in: [packages/form-core/src/FieldApi.ts:415](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L415) The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -141,7 +173,7 @@ The field name. The type will be `DeepKeys` to ensure your name is optional validatorAdapter: TFieldValidator; ``` -Defined in: [packages/form-core/src/FieldApi.ts:315](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L315) +Defined in: [packages/form-core/src/FieldApi.ts:431](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L431) A validator provided by an extension, like `yupValidator` from `@tanstack/yup-form-adapter` @@ -154,10 +186,10 @@ A validator provided by an extension, like `yupValidator` from `@tanstack/yup-fo ### validators? ```ts -optional validators: FieldValidators; +optional validators: FieldValidators; ``` -Defined in: [packages/form-core/src/FieldApi.ts:319](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L319) +Defined in: [packages/form-core/src/FieldApi.ts:435](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L435) A list of validators to pass to the field diff --git a/docs/reference/interfaces/fieldlisteners.md b/docs/reference/interfaces/fieldlisteners.md index c72b78d03..8273470e5 100644 --- a/docs/reference/interfaces/fieldlisteners.md +++ b/docs/reference/interfaces/fieldlisteners.md @@ -3,9 +3,11 @@ id: FieldListeners title: FieldListeners --- + + # Interface: FieldListeners\ -Defined in: [packages/form-core/src/FieldApi.ts:241](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L241) +Defined in: [packages/form-core/src/FieldApi.ts:350](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L350) ## Type Parameters @@ -29,7 +31,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:241](https://github.com/TanStack optional onBlur: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:259](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L259) +Defined in: [packages/form-core/src/FieldApi.ts:368](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L368) *** @@ -39,7 +41,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:259](https://github.com/TanStack optional onChange: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:252](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L252) +Defined in: [packages/form-core/src/FieldApi.ts:361](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L361) *** @@ -49,7 +51,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:252](https://github.com/TanStack optional onMount: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:266](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L266) +Defined in: [packages/form-core/src/FieldApi.ts:375](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L375) *** @@ -59,4 +61,4 @@ Defined in: [packages/form-core/src/FieldApi.ts:266](https://github.com/TanStack optional onSubmit: FieldListenerFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:273](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L273) +Defined in: [packages/form-core/src/FieldApi.ts:382](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L382) diff --git a/docs/reference/interfaces/fieldoptions.md b/docs/reference/interfaces/fieldoptions.md index cdcdaaa80..d3df36c28 100644 --- a/docs/reference/interfaces/fieldoptions.md +++ b/docs/reference/interfaces/fieldoptions.md @@ -3,9 +3,11 @@ id: FieldOptions title: FieldOptions --- -# Interface: FieldOptions\ + -Defined in: [packages/form-core/src/FieldApi.ts:285](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L285) +# Interface: FieldOptions\ + +Defined in: [packages/form-core/src/FieldApi.ts:394](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L394) An object type representing the options for a field in a form. @@ -27,6 +29,20 @@ An object type representing the options for a field in a form. • **TData** *extends* [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> = [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Properties ### asyncAlways? @@ -35,7 +51,7 @@ An object type representing the options for a field in a form. optional asyncAlways: boolean; ``` -Defined in: [packages/form-core/src/FieldApi.ts:311](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L311) +Defined in: [packages/form-core/src/FieldApi.ts:427](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L427) If `true`, always run async validation, even if there are errors emitted during synchronous validation. @@ -47,7 +63,7 @@ If `true`, always run async validation, even if there are errors emitted during optional asyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:307](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L307) +Defined in: [packages/form-core/src/FieldApi.ts:423](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L423) The default time to debounce async validation if there is not a more specific debounce time passed. @@ -56,10 +72,10 @@ The default time to debounce async validation if there is not a more specific de ### defaultMeta? ```ts -optional defaultMeta: Partial; +optional defaultMeta: Partial>; ``` -Defined in: [packages/form-core/src/FieldApi.ts:329](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L329) +Defined in: [packages/form-core/src/FieldApi.ts:452](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L452) An optional object with default metadata for the field. @@ -71,7 +87,7 @@ An optional object with default metadata for the field. optional defaultValue: NoInfer; ``` -Defined in: [packages/form-core/src/FieldApi.ts:303](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L303) +Defined in: [packages/form-core/src/FieldApi.ts:419](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L419) An optional default value for the field. @@ -83,7 +99,7 @@ An optional default value for the field. optional listeners: FieldListeners; ``` -Defined in: [packages/form-core/src/FieldApi.ts:333](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L333) +Defined in: [packages/form-core/src/FieldApi.ts:456](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L456) A list of listeners which attach to the corresponding events @@ -95,7 +111,7 @@ A list of listeners which attach to the corresponding events name: TName; ``` -Defined in: [packages/form-core/src/FieldApi.ts:299](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L299) +Defined in: [packages/form-core/src/FieldApi.ts:415](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L415) The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -107,7 +123,7 @@ The field name. The type will be `DeepKeys` to ensure your name is optional validatorAdapter: TFieldValidator; ``` -Defined in: [packages/form-core/src/FieldApi.ts:315](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L315) +Defined in: [packages/form-core/src/FieldApi.ts:431](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L431) A validator provided by an extension, like `yupValidator` from `@tanstack/yup-form-adapter` @@ -116,9 +132,9 @@ A validator provided by an extension, like `yupValidator` from `@tanstack/yup-fo ### validators? ```ts -optional validators: FieldValidators; +optional validators: FieldValidators; ``` -Defined in: [packages/form-core/src/FieldApi.ts:319](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L319) +Defined in: [packages/form-core/src/FieldApi.ts:435](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L435) A list of validators to pass to the field diff --git a/docs/reference/interfaces/fieldvalidators.md b/docs/reference/interfaces/fieldvalidators.md index 2f34e46a9..0bb03a67a 100644 --- a/docs/reference/interfaces/fieldvalidators.md +++ b/docs/reference/interfaces/fieldvalidators.md @@ -3,9 +3,11 @@ id: FieldValidators title: FieldValidators --- -# Interface: FieldValidators\ + -Defined in: [packages/form-core/src/FieldApi.ts:119](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L119) +# Interface: FieldValidators\ + +Defined in: [packages/form-core/src/FieldApi.ts:214](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L214) ## Type Parameters @@ -21,15 +23,29 @@ Defined in: [packages/form-core/src/FieldApi.ts:119](https://github.com/TanStack • **TData** *extends* [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> = [`DeepValue`](../type-aliases/deepvalue.md)\<`TParentData`, `TName`\> +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Properties ### onBlur? ```ts -optional onBlur: FieldValidateOrFn; +optional onBlur: FieldValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:182](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L182) +Defined in: [packages/form-core/src/FieldApi.ts:287](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L287) An optional function, that runs on the blur event of input. If `validatorAdapter` is passed, this may also accept a property from the respective adapter @@ -45,10 +61,10 @@ z.string().min(1) // if `zodAdapter` is passed ### onBlurAsync? ```ts -optional onBlurAsync: FieldAsyncValidateOrFn; +optional onBlurAsync: FieldAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:195](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L195) +Defined in: [packages/form-core/src/FieldApi.ts:301](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L301) An optional property similar to `onBlur` but async validation. If `validatorAdapter` is passed, this may also accept a property from the respective adapter @@ -67,7 +83,7 @@ z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' }) // optional onBlurAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:208](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L208) +Defined in: [packages/form-core/src/FieldApi.ts:315](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L315) An optional number to represent how long the `onBlurAsync` should wait before running @@ -81,7 +97,7 @@ If set to a number larger than 0, will debounce the async validation event by th optional onBlurListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never[]; ``` -Defined in: [packages/form-core/src/FieldApi.ts:212](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L212) +Defined in: [packages/form-core/src/FieldApi.ts:319](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L319) An optional list of field names that should trigger this field's `onBlur` and `onBlurAsync` events when its value changes @@ -90,10 +106,10 @@ An optional list of field names that should trigger this field's `onBlur` and `o ### onChange? ```ts -optional onChange: FieldValidateOrFn; +optional onChange: FieldValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:146](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L146) +Defined in: [packages/form-core/src/FieldApi.ts:249](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L249) An optional property that takes a `ValidateFn` which is a generic of `TData` and `TParentData`. If `validatorAdapter` is passed, this may also accept a property from the respective adapter @@ -109,10 +125,10 @@ z.string().min(1) // if `zodAdapter` is passed ### onChangeAsync? ```ts -optional onChangeAsync: FieldAsyncValidateOrFn; +optional onChangeAsync: FieldAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:159](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L159) +Defined in: [packages/form-core/src/FieldApi.ts:263](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L263) An optional property similar to `onChange` but async validation. If `validatorAdapter` is passed, this may also accept a property from the respective adapter @@ -131,7 +147,7 @@ z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' }) // optional onChangeAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FieldApi.ts:171](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L171) +Defined in: [packages/form-core/src/FieldApi.ts:276](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L276) An optional number to represent how long the `onChangeAsync` should wait before running @@ -145,7 +161,7 @@ If set to a number larger than 0, will debounce the async validation event by th optional onChangeListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple ? PrefixTupleAccessor, AllowedIndexes, never>, []> : TParentData extends any[] ? PrefixArrayAccessor, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor, []> : TParentData extends string | number | bigint | boolean ? "" : never[]; ``` -Defined in: [packages/form-core/src/FieldApi.ts:175](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L175) +Defined in: [packages/form-core/src/FieldApi.ts:280](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L280) An optional list of field names that should trigger this field's `onChange` and `onChangeAsync` events when its value changes @@ -154,10 +170,10 @@ An optional list of field names that should trigger this field's `onChange` and ### onMount? ```ts -optional onMount: FieldValidateOrFn; +optional onMount: FieldValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:133](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L133) +Defined in: [packages/form-core/src/FieldApi.ts:235](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L235) An optional function that takes a param of `formApi` which is a generic type of `TData` and `TParentData` @@ -166,10 +182,10 @@ An optional function that takes a param of `formApi` which is a generic type of ### onSubmit? ```ts -optional onSubmit: FieldValidateOrFn; +optional onSubmit: FieldValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:219](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L219) +Defined in: [packages/form-core/src/FieldApi.ts:326](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L326) An optional function, that runs on the submit event of form. If `validatorAdapter` is passed, this may also accept a property from the respective adapter @@ -185,10 +201,10 @@ z.string().min(1) // if `zodAdapter` is passed ### onSubmitAsync? ```ts -optional onSubmitAsync: FieldAsyncValidateOrFn; +optional onSubmitAsync: FieldAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FieldApi.ts:232](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L232) +Defined in: [packages/form-core/src/FieldApi.ts:340](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L340) An optional property similar to `onSubmit` but async validation. If `validatorAdapter` is passed, this may also accept a property from the respective adapter diff --git a/docs/reference/interfaces/formoptions.md b/docs/reference/interfaces/formoptions.md index c218321cf..7f7322f12 100644 --- a/docs/reference/interfaces/formoptions.md +++ b/docs/reference/interfaces/formoptions.md @@ -3,9 +3,11 @@ id: FormOptions title: FormOptions --- -# Interface: FormOptions\ + -Defined in: [packages/form-core/src/FormApi.ts:148](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L148) +# Interface: FormOptions\ + +Defined in: [packages/form-core/src/FormApi.ts:247](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L247) An object representing the options for a form. @@ -15,6 +17,22 @@ An object representing the options for a form. • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + ## Properties ### asyncAlways? @@ -23,7 +41,7 @@ An object representing the options for a form. optional asyncAlways: boolean; ``` -Defined in: [packages/form-core/src/FormApi.ts:163](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L163) +Defined in: [packages/form-core/src/FormApi.ts:282](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L282) If true, always run async validation, even when sync validation has produced an error. Defaults to undefined. @@ -35,7 +53,7 @@ If true, always run async validation, even when sync validation has produced an optional asyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FormApi.ts:167](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L167) +Defined in: [packages/form-core/src/FormApi.ts:286](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L286) Optional time in milliseconds if you want to introduce a delay before firing off an async action. @@ -44,10 +62,10 @@ Optional time in milliseconds if you want to introduce a delay before firing off ### defaultState? ```ts -optional defaultState: Partial>; +optional defaultState: Partial>; ``` -Defined in: [packages/form-core/src/FormApi.ts:159](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L159) +Defined in: [packages/form-core/src/FormApi.ts:266](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L266) The default state for the form. @@ -59,7 +77,7 @@ The default state for the form. optional defaultValues: TFormData; ``` -Defined in: [packages/form-core/src/FormApi.ts:155](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L155) +Defined in: [packages/form-core/src/FormApi.ts:262](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L262) Set initial values for your form. @@ -71,7 +89,7 @@ Set initial values for your form. optional onSubmit: (props) => any; ``` -Defined in: [packages/form-core/src/FormApi.ts:179](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L179) +Defined in: [packages/form-core/src/FormApi.ts:308](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L308) A function to be called when the form is submitted, what should happen once the user submits a valid form returns `any` or a promise `Promise` @@ -81,7 +99,7 @@ A function to be called when the form is submitted, what should happen once the ###### formApi -[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`\> +[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ###### value @@ -99,7 +117,7 @@ A function to be called when the form is submitted, what should happen once the optional onSubmitInvalid: (props) => void; ``` -Defined in: [packages/form-core/src/FormApi.ts:186](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L186) +Defined in: [packages/form-core/src/FormApi.ts:326](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L326) Specify an action for scenarios where the user tries to submit an invalid form. @@ -109,7 +127,7 @@ Specify an action for scenarios where the user tries to submit an invalid form. ###### formApi -[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`\> +[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`, `TOnMountReturn`, `TOnChangeReturn`, `TOnChangeAsyncReturn`, `TOnBlurReturn`, `TOnBlurAsyncReturn`, `TOnSubmitReturn`, `TOnSubmitAsyncReturn`, `TOnServerReturn`\> ###### value @@ -124,10 +142,10 @@ Specify an action for scenarios where the user tries to submit an invalid form. ### transform? ```ts -optional transform: FormTransform; +optional transform: FormTransform; ``` -Defined in: [packages/form-core/src/FormApi.ts:190](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L190) +Defined in: [packages/form-core/src/FormApi.ts:341](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L341) *** @@ -137,7 +155,7 @@ Defined in: [packages/form-core/src/FormApi.ts:190](https://github.com/TanStack/ optional validatorAdapter: TFormValidator; ``` -Defined in: [packages/form-core/src/FormApi.ts:171](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L171) +Defined in: [packages/form-core/src/FormApi.ts:290](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L290) A validator adapter to support usage of extra validation types (IE: Zod, Yup, or Valibot usage) @@ -146,9 +164,9 @@ A validator adapter to support usage of extra validation types (IE: Zod, Yup, or ### validators? ```ts -optional validators: FormValidators; +optional validators: FormValidators; ``` -Defined in: [packages/form-core/src/FormApi.ts:175](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L175) +Defined in: [packages/form-core/src/FormApi.ts:294](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L294) A list of validators to pass to the form diff --git a/docs/reference/interfaces/formvalidators.md b/docs/reference/interfaces/formvalidators.md index fef4ad759..f289669eb 100644 --- a/docs/reference/interfaces/formvalidators.md +++ b/docs/reference/interfaces/formvalidators.md @@ -3,9 +3,11 @@ id: FormValidators title: FormValidators --- -# Interface: FormValidators\ + -Defined in: [packages/form-core/src/FormApi.ts:96](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L96) +# Interface: FormValidators\ + +Defined in: [packages/form-core/src/FormApi.ts:146](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L146) ## Type Parameters @@ -13,15 +15,29 @@ Defined in: [packages/form-core/src/FormApi.ts:96](https://github.com/TanStack/f • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Properties ### onBlur? ```ts -optional onBlur: FormValidateOrFn; +optional onBlur: FormValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:119](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L119) +Defined in: [packages/form-core/src/FormApi.ts:180](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L180) Optional function that validates the form data when a field loses focus, returns a `FormValidationError` @@ -30,10 +46,10 @@ Optional function that validates the form data when a field loses focus, returns ### onBlurAsync? ```ts -optional onBlurAsync: FormAsyncValidateOrFn; +optional onBlurAsync: FormAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:123](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L123) +Defined in: [packages/form-core/src/FormApi.ts:184](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L184) Optional onBlur asynchronous validation method for when a field loses focus returns a ` FormValidationError` or a promise of `Promise` @@ -45,7 +61,7 @@ Optional onBlur asynchronous validation method for when a field loses focus retu optional onBlurAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FormApi.ts:127](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L127) +Defined in: [packages/form-core/src/FormApi.ts:192](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L192) The default time in milliseconds that if set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds. @@ -54,10 +70,10 @@ The default time in milliseconds that if set to a number larger than 0, will deb ### onChange? ```ts -optional onChange: FormValidateOrFn; +optional onChange: FormValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:107](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L107) +Defined in: [packages/form-core/src/FormApi.ts:164](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L164) Optional function that checks the validity of your data whenever a value changes @@ -66,10 +82,10 @@ Optional function that checks the validity of your data whenever a value changes ### onChangeAsync? ```ts -optional onChangeAsync: FormAsyncValidateOrFn; +optional onChangeAsync: FormAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:111](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L111) +Defined in: [packages/form-core/src/FormApi.ts:168](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L168) Optional onChange asynchronous counterpart to onChange. Useful for more complex validation logic that might involve server requests. @@ -81,7 +97,7 @@ Optional onChange asynchronous counterpart to onChange. Useful for more complex optional onChangeAsyncDebounceMs: number; ``` -Defined in: [packages/form-core/src/FormApi.ts:115](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L115) +Defined in: [packages/form-core/src/FormApi.ts:176](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L176) The default time in milliseconds that if set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds. @@ -90,10 +106,10 @@ The default time in milliseconds that if set to a number larger than 0, will deb ### onMount? ```ts -optional onMount: FormValidateOrFn; +optional onMount: FormValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:103](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L103) +Defined in: [packages/form-core/src/FormApi.ts:160](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L160) Optional function that fires as soon as the component mounts. @@ -102,17 +118,17 @@ Optional function that fires as soon as the component mounts. ### onSubmit? ```ts -optional onSubmit: FormValidateOrFn; +optional onSubmit: FormValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:128](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L128) +Defined in: [packages/form-core/src/FormApi.ts:193](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L193) *** ### onSubmitAsync? ```ts -optional onSubmitAsync: FormAsyncValidateOrFn; +optional onSubmitAsync: FormAsyncValidateOrFn; ``` -Defined in: [packages/form-core/src/FormApi.ts:129](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L129) +Defined in: [packages/form-core/src/FormApi.ts:194](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L194) diff --git a/docs/reference/type-aliases/anyfieldapi.md b/docs/reference/type-aliases/anyfieldapi.md new file mode 100644 index 000000000..dac960bd1 --- /dev/null +++ b/docs/reference/type-aliases/anyfieldapi.md @@ -0,0 +1,16 @@ +--- +id: AnyFieldApi +title: AnyFieldApi +--- + + + +# Type Alias: AnyFieldApi + +```ts +type AnyFieldApi = FieldApi; +``` + +Defined in: [packages/form-core/src/FieldApi.ts:653](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L653) + +A type representing the Field API with all generics set to `any` for convenience. diff --git a/docs/reference/type-aliases/anyformapi.md b/docs/reference/type-aliases/anyformapi.md new file mode 100644 index 000000000..72c0b13dc --- /dev/null +++ b/docs/reference/type-aliases/anyformapi.md @@ -0,0 +1,16 @@ +--- +id: AnyFormApi +title: AnyFormApi +--- + + + +# Type Alias: AnyFormApi + +```ts +type AnyFormApi = FormApi; +``` + +Defined in: [packages/form-core/src/FormApi.ts:614](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L614) + +A type representing the Form API with all generics set to `any` for convenience. diff --git a/docs/reference/type-aliases/baseformstate.md b/docs/reference/type-aliases/baseformstate.md index 151fd0048..6587565c9 100644 --- a/docs/reference/type-aliases/baseformstate.md +++ b/docs/reference/type-aliases/baseformstate.md @@ -3,13 +3,15 @@ id: BaseFormState title: BaseFormState --- -# Type Alias: BaseFormState\ + + +# Type Alias: BaseFormState\ ```ts -type BaseFormState = object; +type BaseFormState = object; ``` -Defined in: [packages/form-core/src/FormApi.ts:228](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L228) +Defined in: [packages/form-core/src/FormApi.ts:390](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L390) An object representing the current state of the form. @@ -17,12 +19,28 @@ An object representing the current state of the form. • **TFormData** +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + ## Type declaration ### errorMap ```ts -errorMap: FormValidationErrorMap; +errorMap: FormValidationErrorMap; ``` The error map for the form itself. diff --git a/docs/reference/type-aliases/deepkeys.md b/docs/reference/type-aliases/deepkeys.md index 974a0dd32..da053d5d4 100644 --- a/docs/reference/type-aliases/deepkeys.md +++ b/docs/reference/type-aliases/deepkeys.md @@ -3,6 +3,8 @@ id: DeepKeys title: DeepKeys --- + + # Type Alias: DeepKeys\ ```ts diff --git a/docs/reference/type-aliases/deepvalue.md b/docs/reference/type-aliases/deepvalue.md index 405c68661..2cbe33aa1 100644 --- a/docs/reference/type-aliases/deepvalue.md +++ b/docs/reference/type-aliases/deepvalue.md @@ -3,6 +3,8 @@ id: DeepValue title: DeepValue --- + + # Type Alias: DeepValue\ ```ts diff --git a/docs/reference/type-aliases/derivedformstate.md b/docs/reference/type-aliases/derivedformstate.md index fc52afa2f..ea70d2296 100644 --- a/docs/reference/type-aliases/derivedformstate.md +++ b/docs/reference/type-aliases/derivedformstate.md @@ -3,18 +3,36 @@ id: DerivedFormState title: DerivedFormState --- -# Type Alias: DerivedFormState\ + + +# Type Alias: DerivedFormState\ ```ts -type DerivedFormState = object; +type DerivedFormState = object; ``` -Defined in: [packages/form-core/src/FormApi.ts:272](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L272) +Defined in: [packages/form-core/src/FormApi.ts:453](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L453) ## Type Parameters • **TFormData** +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` + ## Type declaration ### canSubmit @@ -28,7 +46,15 @@ A boolean indicating if the form can be submitted based on its current state. ### errors ```ts -errors: ValidationError[]; +errors: ( + | TOnMountReturn + | TOnChangeReturn + | TOnChangeAsyncReturn + | TOnBlurReturn + | TOnBlurAsyncReturn + | TOnSubmitReturn + | TOnSubmitAsyncReturn + | TOnServerReturn)[]; ``` The error array for the form itself. diff --git a/docs/reference/type-aliases/fieldinfo.md b/docs/reference/type-aliases/fieldinfo.md index 2b3a375ba..8ec087938 100644 --- a/docs/reference/type-aliases/fieldinfo.md +++ b/docs/reference/type-aliases/fieldinfo.md @@ -3,13 +3,15 @@ id: FieldInfo title: FieldInfo --- + + # Type Alias: FieldInfo\ ```ts type FieldInfo = object; ``` -Defined in: [packages/form-core/src/FormApi.ts:206](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L206) +Defined in: [packages/form-core/src/FormApi.ts:368](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L368) An object representing the field information for a specific field within the form. diff --git a/docs/reference/type-aliases/fieldmeta.md b/docs/reference/type-aliases/fieldmeta.md index 92d188bea..83cd8a971 100644 --- a/docs/reference/type-aliases/fieldmeta.md +++ b/docs/reference/type-aliases/fieldmeta.md @@ -3,12 +3,30 @@ id: FieldMeta title: FieldMeta --- -# Type Alias: FieldMeta + + +# Type Alias: FieldMeta\ ```ts -type FieldMeta = FieldMetaBase & FieldMetaDerived; +type FieldMeta = FieldMetaBase & FieldMetaDerived; ``` -Defined in: [packages/form-core/src/FieldApi.ts:402](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L402) +Defined in: [packages/form-core/src/FieldApi.ts:590](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L590) An object type representing the metadata of a field in a form. + +## Type Parameters + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` diff --git a/docs/reference/type-aliases/fieldmetabase.md b/docs/reference/type-aliases/fieldmetabase.md index a09bbb5cf..4eda06dc1 100644 --- a/docs/reference/type-aliases/fieldmetabase.md +++ b/docs/reference/type-aliases/fieldmetabase.md @@ -3,20 +3,38 @@ id: FieldMetaBase title: FieldMetaBase --- -# Type Alias: FieldMetaBase + + +# Type Alias: FieldMetaBase\ ```ts -type FieldMetaBase = object; +type FieldMetaBase = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:365](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L365) +Defined in: [packages/form-core/src/FieldApi.ts:521](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L521) + +## Type Parameters + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` ## Type declaration ### errorMap ```ts -errorMap: ValidationErrorMap; +errorMap: ValidationErrorMap; ``` A map of errors related to the field value. diff --git a/docs/reference/type-aliases/fieldmetaderived.md b/docs/reference/type-aliases/fieldmetaderived.md index 1228a198f..ff8487a8d 100644 --- a/docs/reference/type-aliases/fieldmetaderived.md +++ b/docs/reference/type-aliases/fieldmetaderived.md @@ -3,20 +3,45 @@ id: FieldMetaDerived title: FieldMetaDerived --- -# Type Alias: FieldMetaDerived + + +# Type Alias: FieldMetaDerived\ ```ts -type FieldMetaDerived = object; +type FieldMetaDerived = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:388](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L388) +Defined in: [packages/form-core/src/FieldApi.ts:560](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L560) + +## Type Parameters + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` ## Type declaration ### errors ```ts -errors: ValidationError[]; +errors: ( + | TOnMountReturn + | TOnChangeReturn + | TOnChangeAsyncReturn + | TOnBlurReturn + | TOnBlurAsyncReturn + | TOnSubmitReturn + | TOnSubmitAsyncReturn)[]; ``` An array of errors related to the field value. diff --git a/docs/reference/type-aliases/fieldserrormapfromvalidator.md b/docs/reference/type-aliases/fieldserrormapfromvalidator.md index a6e543c07..30a5d0e39 100644 --- a/docs/reference/type-aliases/fieldserrormapfromvalidator.md +++ b/docs/reference/type-aliases/fieldserrormapfromvalidator.md @@ -3,14 +3,30 @@ id: FieldsErrorMapFromValidator title: FieldsErrorMapFromValidator --- -# Type Alias: FieldsErrorMapFromValidator\ + + +# Type Alias: FieldsErrorMapFromValidator\ ```ts -type FieldsErrorMapFromValidator = Partial, ValidationErrorMap>>; +type FieldsErrorMapFromValidator = Partial, ValidationErrorMap>>; ``` -Defined in: [packages/form-core/src/FormApi.ts:31](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L31) +Defined in: [packages/form-core/src/FormApi.ts:33](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L33) ## Type Parameters • **TFormData** + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` diff --git a/docs/reference/type-aliases/fieldstate.md b/docs/reference/type-aliases/fieldstate.md index 30edf86ef..37b8a8123 100644 --- a/docs/reference/type-aliases/fieldstate.md +++ b/docs/reference/type-aliases/fieldstate.md @@ -3,13 +3,15 @@ id: FieldState title: FieldState --- -# Type Alias: FieldState\ + + +# Type Alias: FieldState\ ```ts -type FieldState = object; +type FieldState = object; ``` -Defined in: [packages/form-core/src/FieldApi.ts:407](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L407) +Defined in: [packages/form-core/src/FieldApi.ts:620](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L620) An object type representing the state of a field. @@ -17,12 +19,26 @@ An object type representing the state of a field. • **TData** +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + ## Type declaration ### meta ```ts -meta: FieldMeta; +meta: FieldMeta; ``` The current metadata of the field. diff --git a/docs/reference/type-aliases/formstate.md b/docs/reference/type-aliases/formstate.md index 42e0e392c..528e2fafc 100644 --- a/docs/reference/type-aliases/formstate.md +++ b/docs/reference/type-aliases/formstate.md @@ -3,14 +3,32 @@ id: FormState title: FormState --- -# Type Alias: FormState\ + + +# Type Alias: FormState\ ```ts -type FormState = BaseFormState & DerivedFormState; +type FormState = BaseFormState & DerivedFormState; ``` -Defined in: [packages/form-core/src/FormApi.ts:323](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L323) +Defined in: [packages/form-core/src/FormApi.ts:523](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L523) ## Type Parameters • **TFormData** + +• **TOnMountReturn** = `undefined` + +• **TOnChangeReturn** = `undefined` + +• **TOnChangeAsyncReturn** = `undefined` + +• **TOnBlurReturn** = `undefined` + +• **TOnBlurAsyncReturn** = `undefined` + +• **TOnSubmitReturn** = `undefined` + +• **TOnSubmitAsyncReturn** = `undefined` + +• **TOnServerReturn** = `undefined` diff --git a/docs/reference/type-aliases/formvalidatefn.md b/docs/reference/type-aliases/formvalidatefn.md index 6c7b87224..ed5f7cdfa 100644 --- a/docs/reference/type-aliases/formvalidatefn.md +++ b/docs/reference/type-aliases/formvalidatefn.md @@ -3,13 +3,15 @@ id: FormValidateFn title: FormValidateFn --- -# Type Alias: FormValidateFn()\ + + +# Type Alias: FormValidateFn()\ ```ts -type FormValidateFn = (props) => FormValidationError; +type FormValidateFn = (props) => TReturnType; ``` -Defined in: [packages/form-core/src/FormApi.ts:35](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L35) +Defined in: [packages/form-core/src/FormApi.ts:57](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L57) ## Type Parameters @@ -17,13 +19,15 @@ Defined in: [packages/form-core/src/FormApi.ts:35](https://github.com/TanStack/f • **TFormValidator** *extends* `Validator`\<`TFormData`, `unknown`\> \| `undefined` = `undefined` +• **TReturnType** = `unknown` + ## Parameters ### props #### formApi -[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`\> +[`FormApi`](../classes/formapi.md)\<`TFormData`, `TFormValidator`, `any`, `any`, `any`, `any`, `any`, `any`, `any`\> #### value @@ -31,4 +35,4 @@ Defined in: [packages/form-core/src/FormApi.ts:35](https://github.com/TanStack/f ## Returns -`FormValidationError`\<`TFormData`\> +`TReturnType` diff --git a/docs/reference/type-aliases/formvalidationerror.md b/docs/reference/type-aliases/formvalidationerror.md new file mode 100644 index 000000000..b336edd83 --- /dev/null +++ b/docs/reference/type-aliases/formvalidationerror.md @@ -0,0 +1,20 @@ +--- +id: FormValidationError +title: FormValidationError +--- + + + +# Type Alias: FormValidationError\ + +```ts +type FormValidationError = + | ValidationError +| SpecialFormValidationError; +``` + +Defined in: [packages/form-core/src/types.ts:81](https://github.com/TanStack/form/blob/main/packages/form-core/src/types.ts#L81) + +## Type Parameters + +• **TFormData** diff --git a/docs/reference/type-aliases/formvalidator.md b/docs/reference/type-aliases/formvalidator.md index 8b5a07b19..934c53ee8 100644 --- a/docs/reference/type-aliases/formvalidator.md +++ b/docs/reference/type-aliases/formvalidator.md @@ -3,13 +3,15 @@ id: FormValidator title: FormValidator --- + + # Type Alias: FormValidator\ ```ts type FormValidator = object; ``` -Defined in: [packages/form-core/src/FormApi.ts:68](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L68) +Defined in: [packages/form-core/src/FormApi.ts:117](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L117) ## Type Parameters @@ -37,7 +39,7 @@ Defined in: [packages/form-core/src/FormApi.ts:68](https://github.com/TanStack/f #### Returns -[`ValidationError`](validationerror.md) +`unknown` ### validateAsync() @@ -55,4 +57,4 @@ Defined in: [packages/form-core/src/FormApi.ts:68](https://github.com/TanStack/f #### Returns -`Promise`\<`FormValidationError`\<`TFormData`\>\> +`Promise`\<`unknown`\> diff --git a/docs/reference/type-aliases/standardschemav1.md b/docs/reference/type-aliases/standardschemav1.md index 041725a53..ab4e74835 100644 --- a/docs/reference/type-aliases/standardschemav1.md +++ b/docs/reference/type-aliases/standardschemav1.md @@ -3,6 +3,8 @@ id: StandardSchemaV1 title: StandardSchemaV1 --- + + # Type Alias: StandardSchemaV1\ ```ts diff --git a/docs/reference/type-aliases/updater.md b/docs/reference/type-aliases/updater.md index c58c78c54..bbbefe1b3 100644 --- a/docs/reference/type-aliases/updater.md +++ b/docs/reference/type-aliases/updater.md @@ -3,6 +3,8 @@ id: Updater title: Updater --- + + # Type Alias: Updater\ ```ts diff --git a/docs/reference/type-aliases/updaterfn.md b/docs/reference/type-aliases/updaterfn.md index 62365f5fa..c0f917772 100644 --- a/docs/reference/type-aliases/updaterfn.md +++ b/docs/reference/type-aliases/updaterfn.md @@ -3,6 +3,8 @@ id: UpdaterFn title: UpdaterFn --- + + # Type Alias: UpdaterFn()\ ```ts diff --git a/docs/reference/type-aliases/validationerror.md b/docs/reference/type-aliases/validationerror.md index 774c3fc0c..87984446d 100644 --- a/docs/reference/type-aliases/validationerror.md +++ b/docs/reference/type-aliases/validationerror.md @@ -3,10 +3,12 @@ id: ValidationError title: ValidationError --- + + # Type Alias: ValidationError ```ts -type ValidationError = undefined | false | null | string; +type ValidationError = unknown; ``` Defined in: [packages/form-core/src/types.ts:3](https://github.com/TanStack/form/blob/main/packages/form-core/src/types.ts#L3) diff --git a/docs/reference/type-aliases/validationmeta.md b/docs/reference/type-aliases/validationmeta.md index 3b882abf6..3f1af3ec8 100644 --- a/docs/reference/type-aliases/validationmeta.md +++ b/docs/reference/type-aliases/validationmeta.md @@ -3,13 +3,15 @@ id: ValidationMeta title: ValidationMeta --- + + # Type Alias: ValidationMeta ```ts type ValidationMeta = object; ``` -Defined in: [packages/form-core/src/FormApi.ts:196](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L196) +Defined in: [packages/form-core/src/FormApi.ts:358](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L358) An object representing the validation metadata for a field. Not intended for public usage. diff --git a/docs/reference/type-aliases/validationsource.md b/docs/reference/type-aliases/validationsource.md index 907c7e33b..0edfb695b 100644 --- a/docs/reference/type-aliases/validationsource.md +++ b/docs/reference/type-aliases/validationsource.md @@ -3,6 +3,8 @@ id: ValidationSource title: ValidationSource --- + + # Type Alias: ValidationSource ```ts diff --git a/examples/lit/simple/package.json b/examples/lit/simple/package.json index d1acb96e0..0d90f89e8 100644 --- a/examples/lit/simple/package.json +++ b/examples/lit/simple/package.json @@ -13,7 +13,7 @@ "lit": "^3.2.1" }, "devDependencies": { - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/lit/ui-libraries/package.json b/examples/lit/ui-libraries/package.json index 57c232150..8e117e4d5 100644 --- a/examples/lit/ui-libraries/package.json +++ b/examples/lit/ui-libraries/package.json @@ -14,7 +14,7 @@ "lit": "^3.2.1" }, "devDependencies": { - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/array/package.json b/examples/react/array/package.json index ae54e2a3f..9ff55de2a 100644 --- a/examples/react/array/package.json +++ b/examples/react/array/package.json @@ -14,10 +14,10 @@ "react-dom": "^19.0.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/compiler/package.json b/examples/react/compiler/package.json index 32b4a7bcd..457069947 100644 --- a/examples/react/compiler/package.json +++ b/examples/react/compiler/package.json @@ -14,12 +14,12 @@ "react-dom": "^19.0.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "babel-plugin-react-compiler": "^19.0.0-beta-0dec889-20241115", - "eslint-plugin-react-compiler": "^19.0.0-beta-0dec889-20241115", - "vite": "^5.4.11" + "babel-plugin-react-compiler": "19.0.0-beta-e552027-20250112", + "eslint-plugin-react-compiler": "19.0.0-beta-e552027-20250112", + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/compiler/src/index.tsx b/examples/react/compiler/src/index.tsx index 67cfca1d3..79c72b804 100644 --- a/examples/react/compiler/src/index.tsx +++ b/examples/react/compiler/src/index.tsx @@ -1,9 +1,9 @@ import { useForm } from '@tanstack/react-form' import * as React from 'react' import { createRoot } from 'react-dom/client' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/field-errors-from-form-validators/package.json b/examples/react/field-errors-from-form-validators/package.json index 4a100caf6..61f6c2bd1 100644 --- a/examples/react/field-errors-from-form-validators/package.json +++ b/examples/react/field-errors-from-form-validators/package.json @@ -14,10 +14,10 @@ "react-dom": "^19.0.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/next-server-actions/package.json b/examples/react/next-server-actions/package.json index f78c64785..d62893e03 100644 --- a/examples/react/next-server-actions/package.json +++ b/examples/react/next-server-actions/package.json @@ -10,14 +10,14 @@ "dependencies": { "@tanstack/react-form": "^0.41.2", "@tanstack/react-store": "^0.7.0", - "next": "15.0.3", + "next": "15.1.4", "react": "^19.0.0", "react-dom": "^19.0.0" }, "devDependencies": { - "@types/node": "^22.10.1", - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/node": "^22.10.6", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "typescript": "5.6.3" } } diff --git a/examples/react/next-server-actions/src/app/client-component.tsx b/examples/react/next-server-actions/src/app/client-component.tsx index 8942b7477..b7e62909c 100644 --- a/examples/react/next-server-actions/src/app/client-component.tsx +++ b/examples/react/next-server-actions/src/app/client-component.tsx @@ -23,7 +23,7 @@ export const ClientComp = () => { return (
form.handleSubmit()}> {formErrors.map((error) => ( -

{error}

+

{error}

))} }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/remix/package.json b/examples/react/remix/package.json index fd58ad697..6d17dabb7 100644 --- a/examples/react/remix/package.json +++ b/examples/react/remix/package.json @@ -19,10 +19,10 @@ }, "devDependencies": { "@remix-run/dev": "^2.15.0", - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-tsconfig-paths": "^5.1.2" }, "engines": { diff --git a/examples/react/simple/package.json b/examples/react/simple/package.json index 3ac172d76..b88f1820c 100644 --- a/examples/react/simple/package.json +++ b/examples/react/simple/package.json @@ -14,10 +14,10 @@ "react-dom": "^19.0.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/simple/src/index.tsx b/examples/react/simple/src/index.tsx index 8e57f3352..79c72b804 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -1,9 +1,9 @@ -import type { FieldApi } from '@tanstack/react-form' import { useForm } from '@tanstack/react-form' import * as React from 'react' import { createRoot } from 'react-dom/client' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/standard-schema/package.json b/examples/react/standard-schema/package.json index 0bdfcd71e..792a3e1d3 100644 --- a/examples/react/standard-schema/package.json +++ b/examples/react/standard-schema/package.json @@ -17,10 +17,10 @@ "zod": "^3.24.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/standard-schema/src/index.tsx b/examples/react/standard-schema/src/index.tsx index 6e463526f..2a114f31b 100644 --- a/examples/react/standard-schema/src/index.tsx +++ b/examples/react/standard-schema/src/index.tsx @@ -4,9 +4,9 @@ import * as React from 'react' import { createRoot } from 'react-dom/client' import * as v from 'valibot' import { z } from 'zod' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/tanstack-start/app.config.ts b/examples/react/tanstack-start/app.config.ts index f2cde2c11..36b964528 100644 --- a/examples/react/tanstack-start/app.config.ts +++ b/examples/react/tanstack-start/app.config.ts @@ -3,7 +3,7 @@ import tsConfigPaths from 'vite-tsconfig-paths' export default defineConfig({ vite: { - plugins: () => [ + plugins: [ tsConfigPaths({ projects: ['./tsconfig.json'], }), diff --git a/examples/react/tanstack-start/app/client.tsx b/examples/react/tanstack-start/app/client.tsx index f16ba73f6..ffee5f382 100644 --- a/examples/react/tanstack-start/app/client.tsx +++ b/examples/react/tanstack-start/app/client.tsx @@ -4,4 +4,4 @@ import { createRouter } from './router' const router = createRouter() -hydrateRoot(document.getElementById('root')!, ) +hydrateRoot(document, ) diff --git a/examples/react/tanstack-start/app/routeTree.gen.ts b/examples/react/tanstack-start/app/routeTree.gen.ts index 5ecc21f20..5e682936b 100644 --- a/examples/react/tanstack-start/app/routeTree.gen.ts +++ b/examples/react/tanstack-start/app/routeTree.gen.ts @@ -1,12 +1,12 @@ -/* prettier-ignore-start */ - /* eslint-disable */ // @ts-nocheck // noinspection JSUnusedGlobalSymbols -// This file is auto-generated by TanStack Router +// This file was automatically generated by TanStack Router. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. // Import Routes @@ -16,6 +16,7 @@ import { Route as IndexImport } from './routes/index' // Create/Update Routes const IndexRoute = IndexImport.update({ + id: '/', path: '/', getParentRoute: () => rootRoute, } as any) @@ -36,9 +37,39 @@ declare module '@tanstack/react-router' { // Create and export the route tree -export const routeTree = rootRoute.addChildren({ IndexRoute }) +export interface FileRoutesByFullPath { + '/': typeof IndexRoute +} + +export interface FileRoutesByTo { + '/': typeof IndexRoute +} + +export interface FileRoutesById { + __root__: typeof rootRoute + '/': typeof IndexRoute +} + +export interface FileRouteTypes { + fileRoutesByFullPath: FileRoutesByFullPath + fullPaths: '/' + fileRoutesByTo: FileRoutesByTo + to: '/' + id: '__root__' | '/' + fileRoutesById: FileRoutesById +} + +export interface RootRouteChildren { + IndexRoute: typeof IndexRoute +} + +const rootRouteChildren: RootRouteChildren = { + IndexRoute: IndexRoute, +} -/* prettier-ignore-end */ +export const routeTree = rootRoute + ._addFileChildren(rootRouteChildren) + ._addFileTypes() /* ROUTE_MANIFEST_START { diff --git a/examples/react/tanstack-start/app/routes/__root.tsx b/examples/react/tanstack-start/app/routes/__root.tsx index 9e824c828..0d2d6abc7 100644 --- a/examples/react/tanstack-start/app/routes/__root.tsx +++ b/examples/react/tanstack-start/app/routes/__root.tsx @@ -1,21 +1,26 @@ -import { createRootRoute } from '@tanstack/react-router' -import { Outlet, ScrollRestoration } from '@tanstack/react-router' -import { Body, Head, Html, Meta, Scripts } from '@tanstack/start' +import { + Outlet, + ScrollRestoration, + createRootRoute, +} from '@tanstack/react-router' +import { Meta, Scripts } from '@tanstack/start' import * as React from 'react' export const Route = createRootRoute({ - meta: () => [ - { - charSet: 'utf-8', - }, - { - name: 'viewport', - content: 'width=device-width, initial-scale=1', - }, - { - title: 'TanStack Form + Start', - }, - ], + head: () => ({ + meta: [ + { + charSet: 'utf-8', + }, + { + name: 'viewport', + content: 'width=device-width, initial-scale=1', + }, + { + title: 'TanStack Form + Start', + }, + ], + }), component: RootComponent, }) @@ -29,15 +34,15 @@ function RootComponent() { function RootDocument({ children }: { children: React.ReactNode }) { return ( - - + + - - + + {children} - - + + ) } diff --git a/examples/react/tanstack-start/app/routes/index.tsx b/examples/react/tanstack-start/app/routes/index.tsx index 0b8e8bb87..3fbc56f67 100644 --- a/examples/react/tanstack-start/app/routes/index.tsx +++ b/examples/react/tanstack-start/app/routes/index.tsx @@ -12,6 +12,7 @@ export const Route = createFileRoute('/')({ function Home() { const { state } = Route.useLoaderData() + const form = useForm({ ...formOpts, transform: useTransform((baseForm) => mergeForm(baseForm, state), [state]), @@ -22,7 +23,7 @@ function Home() { return ( {formErrors.map((error) => ( -

{error}

+

{error}

))} { +export const handleForm = createServerFn({ + method: 'POST', +}) + .validator((data: unknown) => { + if (!(data instanceof FormData)) { + throw new Error('Invalid form data') + } + return data + }) + .handler(async (ctx) => { try { - await serverValidate(ctx, formData) + await serverValidate(ctx.data) } catch (e) { if (e instanceof ServerValidateError) { + // Log form errors or do any other logic here return e.response } // Some other error occurred when parsing the form console.error(e) - return new Response('There was an internal error', { - status: 500, - }) + setResponseStatus(500) + return 'There was an internal error' } - return new Response('Form has validated successfully', { - status: 200, - }) + return 'Form has validated successfully' + }) + +export const getFormDataFromServer = createServerFn({ method: 'GET' }).handler( + async () => { + return getFormData() }, ) - -export const getFormDataFromServer = createServerFn('GET', async (_, ctx) => { - return getFormData(ctx) -}) diff --git a/examples/react/tanstack-start/package.json b/examples/react/tanstack-start/package.json index b7359005f..8a376acc0 100644 --- a/examples/react/tanstack-start/package.json +++ b/examples/react/tanstack-start/package.json @@ -11,20 +11,20 @@ "dependencies": { "@tanstack/form-core": "^0.41.2", "@tanstack/react-form": "^0.41.2", - "@tanstack/react-router": "^1.81.1", + "@tanstack/react-router": "^1.95.6", "@tanstack/react-store": "^0.7.0", - "@tanstack/start": "^1.81.1", + "@tanstack/start": "^1.95.7", "react": "^19.0.0", "react-dom": "^19.0.0", - "vinxi": "^0.4.3" + "vinxi": "^0.5.1" }, "devDependencies": { - "@types/node": "^22.10.1", - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/node": "^22.10.6", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-tsconfig-paths": "^5.1.2" } } diff --git a/examples/react/ui-libraries/package.json b/examples/react/ui-libraries/package.json index a739304b2..42d13ca3a 100644 --- a/examples/react/ui-libraries/package.json +++ b/examples/react/ui-libraries/package.json @@ -9,26 +9,26 @@ "test:types": "tsc --noEmit" }, "dependencies": { - "@emotion/react": "11.13.3", - "@emotion/styled": "11.13.0", - "@mantine/core": "7.13.5", - "@mantine/hooks": "7.13.5", - "@mui/material": "5.16.7", + "@emotion/react": "11.14.0", + "@emotion/styled": "11.14.0", + "@mantine/core": "7.16.0", + "@mantine/hooks": "7.16.0", + "@mui/material": "6.4.0", "@tanstack/react-form": "^0.41.2", "@yme/lay-postcss": "0.1.0", - "postcss": "8.4.48", + "postcss": "8.5.1", "postcss-preset-mantine": "1.17.0", "postcss-simple-vars": "7.0.1", "react": "^19.0.0", "react-dom": "^19.0.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", "@vitejs/plugin-react-swc": "^3.7.1", "typescript": "5.6.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/valibot/package.json b/examples/react/valibot/package.json index b460dcec2..e24eb891f 100644 --- a/examples/react/valibot/package.json +++ b/examples/react/valibot/package.json @@ -16,10 +16,10 @@ "valibot": "^1.0.0-beta.9" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/valibot/src/index.tsx b/examples/react/valibot/src/index.tsx index 7236e82ed..690be8e12 100644 --- a/examples/react/valibot/src/index.tsx +++ b/examples/react/valibot/src/index.tsx @@ -3,9 +3,9 @@ import { createRoot } from 'react-dom/client' import { useForm } from '@tanstack/react-form' import { valibotValidator } from '@tanstack/valibot-form-adapter' import * as v from 'valibot' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/yup/package.json b/examples/react/yup/package.json index c459bfd25..2b20bafbc 100644 --- a/examples/react/yup/package.json +++ b/examples/react/yup/package.json @@ -16,10 +16,10 @@ "yup": "^1.5.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/yup/src/index.tsx b/examples/react/yup/src/index.tsx index f3fa3f44e..781d13dd8 100644 --- a/examples/react/yup/src/index.tsx +++ b/examples/react/yup/src/index.tsx @@ -3,9 +3,9 @@ import { createRoot } from 'react-dom/client' import { useForm } from '@tanstack/react-form' import { yupValidator } from '@tanstack/yup-form-adapter' import * as yup from 'yup' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/react/zod/package.json b/examples/react/zod/package.json index 9a940274e..f4477b48c 100644 --- a/examples/react/zod/package.json +++ b/examples/react/zod/package.json @@ -16,10 +16,10 @@ "zod": "^3.24.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-dom": "^19.0.0", + "@types/react": "^19.0.7", + "@types/react-dom": "^19.0.3", "@vitejs/plugin-react": "^4.3.3", - "vite": "^5.4.11" + "vite": "^5.1.8" }, "browserslist": { "production": [ diff --git a/examples/react/zod/src/index.tsx b/examples/react/zod/src/index.tsx index 1f92a6bee..6cd82f097 100644 --- a/examples/react/zod/src/index.tsx +++ b/examples/react/zod/src/index.tsx @@ -3,9 +3,9 @@ import { createRoot } from 'react-dom/client' import { useForm } from '@tanstack/react-form' import { zodValidator } from '@tanstack/zod-form-adapter' import { z } from 'zod' -import type { FieldApi } from '@tanstack/react-form' +import type { AnyFieldApi } from '@tanstack/react-form' -function FieldInfo({ field }: { field: FieldApi }) { +function FieldInfo({ field }: { field: AnyFieldApi }) { return ( <> {field.state.meta.isTouched && field.state.meta.errors.length ? ( diff --git a/examples/solid/array/package.json b/examples/solid/array/package.json index ed660e774..741f92db2 100644 --- a/examples/solid/array/package.json +++ b/examples/solid/array/package.json @@ -10,11 +10,11 @@ }, "dependencies": { "@tanstack/solid-form": "^0.41.2", - "solid-js": "^1.9.3" + "solid-js": "^1.9.4" }, "devDependencies": { "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-plugin-solid": "^2.11.0" } } diff --git a/examples/solid/simple/package.json b/examples/solid/simple/package.json index dea48224d..4189bfdcd 100644 --- a/examples/solid/simple/package.json +++ b/examples/solid/simple/package.json @@ -10,11 +10,11 @@ }, "dependencies": { "@tanstack/solid-form": "^0.41.2", - "solid-js": "^1.9.3" + "solid-js": "^1.9.4" }, "devDependencies": { "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-plugin-solid": "^2.11.0" } } diff --git a/examples/solid/simple/src/index.tsx b/examples/solid/simple/src/index.tsx index 740dc0e78..480787f02 100644 --- a/examples/solid/simple/src/index.tsx +++ b/examples/solid/simple/src/index.tsx @@ -2,10 +2,10 @@ import { render } from 'solid-js/web' import { createForm } from '@tanstack/solid-form' -import type { FieldApi } from '@tanstack/solid-form' +import type { AnyFieldApi } from '@tanstack/solid-form' interface FieldInfoProps { - field: FieldApi + field: AnyFieldApi } function FieldInfo(props: FieldInfoProps) { diff --git a/examples/solid/valibot/package.json b/examples/solid/valibot/package.json index 0a15267ea..8c46c78f4 100644 --- a/examples/solid/valibot/package.json +++ b/examples/solid/valibot/package.json @@ -11,12 +11,12 @@ "dependencies": { "@tanstack/solid-form": "^0.41.2", "@tanstack/valibot-form-adapter": "^0.41.2", - "solid-js": "^1.9.3", + "solid-js": "^1.9.4", "valibot": "^1.0.0-beta.9" }, "devDependencies": { "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-plugin-solid": "^2.11.0" } } diff --git a/examples/solid/valibot/src/index.tsx b/examples/solid/valibot/src/index.tsx index a1b0ee3f0..e0c4c77f0 100644 --- a/examples/solid/valibot/src/index.tsx +++ b/examples/solid/valibot/src/index.tsx @@ -4,10 +4,10 @@ import { render } from 'solid-js/web' import { createForm } from '@tanstack/solid-form' import { valibotValidator } from '@tanstack/valibot-form-adapter' import * as v from 'valibot' -import type { FieldApi } from '@tanstack/solid-form' +import type { AnyFieldApi } from '@tanstack/solid-form' interface FieldInfoProps { - field: FieldApi + field: AnyFieldApi } function FieldInfo(props: FieldInfoProps) { diff --git a/examples/solid/yup/package.json b/examples/solid/yup/package.json index b5e4fa844..0a5d5c055 100644 --- a/examples/solid/yup/package.json +++ b/examples/solid/yup/package.json @@ -11,12 +11,12 @@ "dependencies": { "@tanstack/solid-form": "^0.41.2", "@tanstack/yup-form-adapter": "^0.41.2", - "solid-js": "^1.9.3", + "solid-js": "^1.9.4", "yup": "^1.5.0" }, "devDependencies": { "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-plugin-solid": "^2.11.0" } } diff --git a/examples/solid/yup/src/index.tsx b/examples/solid/yup/src/index.tsx index 86f303e3b..4cf2ebf11 100644 --- a/examples/solid/yup/src/index.tsx +++ b/examples/solid/yup/src/index.tsx @@ -4,10 +4,10 @@ import { render } from 'solid-js/web' import { createForm } from '@tanstack/solid-form' import { yupValidator } from '@tanstack/yup-form-adapter' import * as yup from 'yup' -import type { FieldApi } from '@tanstack/solid-form' +import type { AnyFieldApi } from '@tanstack/solid-form' interface FieldInfoProps { - field: FieldApi + field: AnyFieldApi } function FieldInfo(props: FieldInfoProps) { diff --git a/examples/solid/zod/package.json b/examples/solid/zod/package.json index f9570524a..1e8723a93 100644 --- a/examples/solid/zod/package.json +++ b/examples/solid/zod/package.json @@ -11,12 +11,12 @@ "dependencies": { "@tanstack/solid-form": "^0.41.2", "@tanstack/zod-form-adapter": "^0.41.2", - "solid-js": "^1.9.3", + "solid-js": "^1.9.4", "zod": "^3.24.0" }, "devDependencies": { "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vite-plugin-solid": "^2.11.0" } } diff --git a/examples/solid/zod/src/index.tsx b/examples/solid/zod/src/index.tsx index 34121192e..3229de819 100644 --- a/examples/solid/zod/src/index.tsx +++ b/examples/solid/zod/src/index.tsx @@ -4,10 +4,10 @@ import { render } from 'solid-js/web' import { createForm } from '@tanstack/solid-form' import { zodValidator } from '@tanstack/zod-form-adapter' import { z } from 'zod' -import type { FieldApi } from '@tanstack/solid-form' +import type { AnyFieldApi } from '@tanstack/solid-form' interface FieldInfoProps { - field: FieldApi + field: AnyFieldApi } function FieldInfo(props: FieldInfoProps) { diff --git a/examples/vue/array/package.json b/examples/vue/array/package.json index ecc5dc787..451d1c358 100644 --- a/examples/vue/array/package.json +++ b/examples/vue/array/package.json @@ -11,12 +11,12 @@ }, "dependencies": { "@tanstack/vue-form": "^0.41.2", - "vue": "^3.5.12" + "vue": "^3.5.13" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vue-tsc": "^2.0.26" } } diff --git a/examples/vue/simple/package.json b/examples/vue/simple/package.json index a22993ed8..2ccb37530 100644 --- a/examples/vue/simple/package.json +++ b/examples/vue/simple/package.json @@ -11,12 +11,12 @@ }, "dependencies": { "@tanstack/vue-form": "^0.41.2", - "vue": "^3.5.12" + "vue": "^3.5.13" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vue-tsc": "^2.0.26" } } diff --git a/examples/vue/simple/src/App.vue b/examples/vue/simple/src/App.vue index 2338de016..1e85c8e97 100644 --- a/examples/vue/simple/src/App.vue +++ b/examples/vue/simple/src/App.vue @@ -30,9 +30,6 @@ async function onChangeFirstName({ value }: { value: string }) { " >
- - - -import { FieldApi } from '@tanstack/vue-form' +import { AnyFieldApi } from '@tanstack/vue-form' const props = defineProps<{ - state: FieldApi['state'] + state: AnyFieldApi['state'] }>() diff --git a/examples/vue/valibot/package.json b/examples/vue/valibot/package.json index 622c8a835..ccf30de04 100644 --- a/examples/vue/valibot/package.json +++ b/examples/vue/valibot/package.json @@ -13,12 +13,12 @@ "@tanstack/valibot-form-adapter": "^0.41.2", "@tanstack/vue-form": "^0.41.2", "valibot": "^1.0.0-beta.9", - "vue": "^3.5.12" + "vue": "^3.5.13" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vue-tsc": "^2.0.26" } } diff --git a/examples/vue/valibot/src/App.vue b/examples/vue/valibot/src/App.vue index ed7b79611..bdefaf0f9 100644 --- a/examples/vue/valibot/src/App.vue +++ b/examples/vue/valibot/src/App.vue @@ -37,9 +37,6 @@ const onChangeFirstName = v.pipeAsync( " >
- - - -import { FieldApi } from '@tanstack/vue-form' +import { AnyFieldApi } from '@tanstack/vue-form' const props = defineProps<{ - state: FieldApi['state'] + state: AnyFieldApi['state'] }>() diff --git a/examples/vue/yup/package.json b/examples/vue/yup/package.json index 7246742ec..3c7c2e3bf 100644 --- a/examples/vue/yup/package.json +++ b/examples/vue/yup/package.json @@ -12,13 +12,13 @@ "dependencies": { "@tanstack/vue-form": "^0.41.2", "@tanstack/yup-form-adapter": "^0.41.2", - "vue": "^3.5.12", + "vue": "^3.5.13", "yup": "^1.5.0" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vue-tsc": "^2.0.26" } } diff --git a/examples/vue/yup/src/App.vue b/examples/vue/yup/src/App.vue index 32d3c59e0..4b154b8f1 100644 --- a/examples/vue/yup/src/App.vue +++ b/examples/vue/yup/src/App.vue @@ -36,9 +36,6 @@ const onChangeFirstName = yup " >
- - - -import { FieldApi } from '@tanstack/vue-form' +import { AnyFieldApi } from '@tanstack/vue-form' const props = defineProps<{ - state: FieldApi['state'] + state: AnyFieldApi['state'] }>() diff --git a/examples/vue/zod/package.json b/examples/vue/zod/package.json index 3d8d484aa..b94f23d46 100644 --- a/examples/vue/zod/package.json +++ b/examples/vue/zod/package.json @@ -12,13 +12,13 @@ "dependencies": { "@tanstack/vue-form": "^0.41.2", "@tanstack/zod-form-adapter": "^0.41.2", - "vue": "^3.5.12", + "vue": "^3.5.13", "zod": "^3.24.0" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", "typescript": "5.6.3", - "vite": "^5.4.11", + "vite": "^5.1.8", "vue-tsc": "^2.0.26" } } diff --git a/examples/vue/zod/src/App.vue b/examples/vue/zod/src/App.vue index 0700e0afd..c4d216eb9 100644 --- a/examples/vue/zod/src/App.vue +++ b/examples/vue/zod/src/App.vue @@ -39,9 +39,6 @@ const onChangeFirstName = z.string().refine( " >
- - - -import { FieldApi } from '@tanstack/vue-form' +import { AnyFieldApi } from '@tanstack/vue-form' const props = defineProps<{ - state: FieldApi['state'] + state: AnyFieldApi['state'] }>() diff --git a/knip.json b/knip.json index e7d196211..5e796abe1 100644 --- a/knip.json +++ b/knip.json @@ -1,5 +1,5 @@ { "$schema": "https://unpkg.com/knip@5/schema.json", - "ignoreDependencies": ["@tanstack/start"], + "ignoreDependencies": ["@tanstack/start", "vinxi"], "ignoreWorkspaces": ["examples/**"] } diff --git a/package.json b/package.json index a5b4f29fa..b7a5c6867 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test:ci": "nx run-many --targets=test:sherif,test:knip,test:eslint,test:lib,test:types,test:build,build", "test:eslint": "nx affected --target=test:eslint", "test:format": "pnpm run prettier --check", - "test:sherif": "sherif -i react -i react-dom", + "test:sherif": "sherif", "test:lib": "nx affected --target=test:lib --exclude=examples/**", "test:lib:dev": "pnpm run test:lib && nx watch --all -- pnpm run test:lib", "test:build": "nx affected --target=test:build --exclude=examples/**", @@ -38,23 +38,23 @@ ] }, "devDependencies": { - "@eslint-react/eslint-plugin": "^1.23.2", + "@eslint-react/eslint-plugin": "^1.17.3", "@solidjs/testing-library": "^0.8.10", - "@tanstack/config": "^0.15.1", + "@tanstack/config": "^0.16.0", "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.1.0", "@testing-library/user-event": "^14.5.2", "@testing-library/vue": "^8.1.0", - "@types/node": "^22.10.1", + "@types/node": "^22.10.6", "@vitest/coverage-istanbul": "^2.1.8", - "eslint": "^9.16.0", + "eslint": "9.18.0", "eslint-plugin-react-hooks": "^5.1.0", - "jsdom": "^25.0.1", + "jsdom": "^26.0.0", "knip": "^5.39.2", - "nx": "^20.2.0", + "nx": "^20.3.1", "premove": "^4.0.0", "prettier": "^3.4.2", - "publint": "^0.2.12", + "publint": "^0.3.2", "sherif": "^1.0.2", "typescript": "5.6.3", "typescript51": "npm:typescript@5.1", @@ -62,7 +62,13 @@ "typescript53": "npm:typescript@5.3", "typescript54": "npm:typescript@5.4", "typescript55": "npm:typescript@5.5", - "vite": "^5.4.11", + "vite": "^5.1.8", "vitest": "^2.1.8" + }, + "pnpm": { + "//": "https://github.com/jsdom/cssstyle/issues/182", + "overrides": { + "cssstyle": "4.1.0" + } } } diff --git a/packages/angular-form/src/inject-form.ts b/packages/angular-form/src/inject-form.ts index 4c5ac3a64..088b511dd 100644 --- a/packages/angular-form/src/inject-form.ts +++ b/packages/angular-form/src/inject-form.ts @@ -5,8 +5,40 @@ import type { FormOptions, Validator } from '@tanstack/form-core' export function injectForm< TFormData, TFormValidator extends Validator | undefined = undefined, ->(opts?: FormOptions) { - const api = new FormApi(opts) + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, +>( + opts?: FormOptions< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >, +) { + const api = new FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >(opts) injectStore(api.store, (state) => state.isSubmitting) diff --git a/packages/angular-form/src/inject-store.ts b/packages/angular-form/src/inject-store.ts index 5d499d836..cebf58178 100644 --- a/packages/angular-form/src/inject-store.ts +++ b/packages/angular-form/src/inject-store.ts @@ -4,10 +4,43 @@ import type { FormApi, FormState, Validator } from '@tanstack/form-core' export function injectStore< TFormData, TFormValidator extends Validator | undefined = undefined, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, TSelected = NoInfer>, >( - form: FormApi, - selector?: (state: NoInfer>) => TSelected, + form: FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >, + selector?: ( + state: NoInfer< + FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + >, + ) => TSelected, ) { return injectAngularStore(form.store, selector) } diff --git a/packages/angular-form/src/tanstack-field.directive.ts b/packages/angular-form/src/tanstack-field.directive.ts index c23fa9189..6ffad7684 100644 --- a/packages/angular-form/src/tanstack-field.directive.ts +++ b/packages/angular-form/src/tanstack-field.directive.ts @@ -4,7 +4,7 @@ import { booleanAttribute, numberAttribute, } from '@angular/core' -import { FieldApi, FormApi } from '@tanstack/form-core' +import { FieldApi, FieldApiOptions, FormApi } from '@tanstack/form-core' import type { OnChanges, OnDestroy, OnInit } from '@angular/core' import type { DeepKeys, @@ -32,12 +32,40 @@ export class TanStackField< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > implements OnInit, OnChanges, OnDestroy, - FieldOptions + FieldOptions< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > { @Input({ required: true }) name!: TName // Setting as NoInferHack as it's the same internal type cast as TanStack Form Core @@ -49,19 +77,82 @@ export class TanStackField< @Input() validatorAdapter?: TFieldValidator @Input({ required: true }) tanstackField!: FormApi< TParentData, - TFormValidator + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn > @Input() validators?: NoInfer< - FieldValidators + FieldValidators< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > > @Input() listeners?: NoInfer< FieldListeners > @Input() defaultMeta?: Partial - api!: FieldApi + api!: FieldApi< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + > - private getOptions() { + private getOptions(): FieldApiOptions< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + > { return { defaultValue: this.defaultValue, asyncDebounceMs: this.asyncDebounceMs, diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index ddb7c993c..2986abb3a 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -30,10 +30,33 @@ export type FieldValidateFn< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TReturnType = unknown, > = (props: { value: TData - fieldApi: FieldApi -}) => ValidationError + fieldApi: FieldApi< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + // This is technically an edge-type; which we try to keep non-`any`, but in this case + // It's referring to an inaccessible type from the field validate function inner types, so it's not a big deal + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any + > +}) => TReturnType /** * @private @@ -48,10 +71,26 @@ export type FieldValidateOrFn< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TReturnType = unknown, > = - | (TFieldValidator extends Validator ? TFN : never) - | (TFormValidator extends Validator ? FFN : never) - | FieldValidateFn + | (TFieldValidator extends Validator + ? TFN + : never) + | (TFormValidator extends Validator< + TParentData, + infer FFN, + infer _TReturnType + > + ? FFN + : never) + | FieldValidateFn< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TReturnType + > | StandardSchemaV1 /** @@ -67,11 +106,34 @@ export type FieldValidateAsyncFn< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TReturnType = unknown, > = (options: { value: TData - fieldApi: FieldApi + fieldApi: FieldApi< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + // This is technically an edge-type; which we try to keep non-`any`, but in this case + // It's referring to an inaccessible type from the field validate function inner types, so it's not a big deal + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any + > signal: AbortSignal -}) => ValidationError | Promise +}) => TReturnType | Promise /** * @private @@ -86,15 +148,25 @@ export type FieldAsyncValidateOrFn< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TReturnType = unknown, > = - | (TFieldValidator extends Validator ? TFN : never) - | (TFormValidator extends Validator ? FFN : never) + | (TFieldValidator extends Validator + ? TFN + : never) + | (TFormValidator extends Validator< + TParentData, + infer FFN, + infer _TReturnType + > + ? FFN + : never) | FieldValidateAsyncFn< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TReturnType > | StandardSchemaV1 @@ -113,7 +185,30 @@ export type FieldListenerFn< TData extends DeepValue = DeepValue, > = (props: { value: TData - fieldApi: FieldApi + fieldApi: FieldApi< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + // This is technically an edge-type; which we try to keep non-`any`, but in this case + // It's referring to an inaccessible type from the field listener function inner types, so it's not a big deal + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any + > }) => void export interface FieldValidators< @@ -126,6 +221,13 @@ export interface FieldValidators< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, > { /** * An optional function that takes a param of `formApi` which is a generic type of `TData` and `TParentData` @@ -135,7 +237,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn > /** * An optional property that takes a `ValidateFn` which is a generic of `TData` and `TParentData`. @@ -148,7 +251,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnChangeReturn > /** * An optional property similar to `onChange` but async validation. If `validatorAdapter` @@ -161,7 +265,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnChangeAsyncReturn > /** * An optional number to represent how long the `onChangeAsync` should wait before running @@ -184,7 +289,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnBlurReturn > /** * An optional property similar to `onBlur` but async validation. If `validatorAdapter` @@ -197,7 +303,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnBlurAsyncReturn > /** @@ -221,7 +328,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnSubmitReturn > /** * An optional property similar to `onSubmit` but async validation. If `validatorAdapter` @@ -234,7 +342,8 @@ export interface FieldValidators< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnSubmitAsyncReturn > } @@ -292,6 +401,13 @@ export interface FieldOptions< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, > { /** * The field name. The type will be `DeepKeys` to ensure your name is a deep key of the parent dataset. @@ -321,7 +437,14 @@ export interface FieldOptions< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn > /** * An optional object with default metadata for the field. @@ -352,17 +475,58 @@ export interface FieldApiOptions< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > extends FieldOptions< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn > { - form: FormApi + form: FormApi< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + > } -export type FieldMetaBase = { +export type FieldMetaBase< + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, +> = { /** * A flag indicating whether the field has been touched. */ @@ -378,18 +542,42 @@ export type FieldMetaBase = { /** * A map of errors related to the field value. */ - errorMap: ValidationErrorMap + errorMap: ValidationErrorMap< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > /** * A flag indicating whether the field is currently being validated. */ isValidating: boolean } -export type FieldMetaDerived = { +export type FieldMetaDerived< + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, +> = { /** * An array of errors related to the field value. */ - errors: ValidationError[] + errors: Array< + | TOnMountReturn + | TOnChangeReturn + | TOnChangeAsyncReturn + | TOnBlurReturn + | TOnBlurAsyncReturn + | TOnSubmitReturn + | TOnSubmitAsyncReturn + > /** * A flag that is `true` if the field's value has not been modified by the user. Opposite of `isDirty`. */ @@ -399,12 +587,46 @@ export type FieldMetaDerived = { /** * An object type representing the metadata of a field in a form. */ -export type FieldMeta = FieldMetaBase & FieldMetaDerived +export type FieldMeta< + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, +> = FieldMetaBase< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn +> & + FieldMetaDerived< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > /** * An object type representing the state of a field. */ -export type FieldState = { +export type FieldState< + TData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, +> = { /** * The current value of the field. */ @@ -412,9 +634,45 @@ export type FieldState = { /** * The current metadata of the field. */ - meta: FieldMeta + meta: FieldMeta< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > } +/** + * @public + * + * A type representing the Field API with all generics set to `any` for convenience. + */ +export type AnyFieldApi = FieldApi< + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any +> + /** * A class representing the API for managing a form field. * @@ -434,6 +692,21 @@ export class FieldApi< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > { /** * A reference to the form API instance. @@ -443,7 +716,22 @@ export class FieldApi< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >['form'] /** * The field name. @@ -457,12 +745,37 @@ export class FieldApi< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn > = {} as any /** * The field state store. */ - store!: Derived> + store!: Derived< + FieldState< + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + > /** * The current field state. */ @@ -480,7 +793,22 @@ export class FieldApi< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) { this.form = opts.form as never @@ -510,7 +838,16 @@ export class FieldApi< return { value, meta, - } as FieldState + } as FieldState< + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > }, }) @@ -523,10 +860,11 @@ export class FieldApi< runValidator< TValue extends { value: TData - fieldApi: FieldApi + fieldApi: AnyFieldApi validationSource: ValidationSource }, TType extends 'validate' | 'validateAsync', + TReturnType = unknown, >(props: { validate: TType extends 'validate' ? FieldValidateOrFn @@ -534,7 +872,7 @@ export class FieldApi< value: TValue type: TType // When `api` is 'field', the return type cannot be `FormValidationError` - }): TType extends 'validate' ? ValidationError : Promise { + }): TType extends 'validate' ? TReturnType : Promise { const adapters = [ this.form.options.validatorAdapter, this.options.validatorAdapter, @@ -584,11 +922,14 @@ export class FieldApi< type: 'validate', }) if (error) { - this.setMeta((prev) => ({ - ...prev, - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - errorMap: { ...prev?.errorMap, onMount: error }, - })) + this.setMeta( + (prev) => + ({ + ...prev, + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + errorMap: { ...prev?.errorMap, onMount: error }, + }) as never, + ) } } @@ -609,7 +950,22 @@ export class FieldApi< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) => { // Default Value @@ -664,8 +1020,19 @@ export class FieldApi< /** * Sets the field metadata. */ - setMeta = (updater: Updater) => - this.form.setFieldMeta(this.name, updater) + setMeta = ( + updater: Updater< + FieldMeta< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + >, + ) => this.form.setFieldMeta(this.name, updater) /** * Gets the field information object. @@ -725,7 +1092,7 @@ export class FieldApi< TFormValidator >[] - const linkedFields: FieldApi[] = [] + const linkedFields: AnyFieldApi[] = [] for (const field of fields) { if (!field.instance) continue const { onChangeListenTo, onBlurListenTo } = @@ -762,7 +1129,31 @@ export class FieldApi< }) return acc.concat(fieldValidates as never) }, - [] as Array & { field: FieldApi }>, + [] as Array< + SyncValidator & { + field: FieldApi< + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any + > + } + >, ) // Needs type cast as eslint errantly believes this is always falsy @@ -770,7 +1161,7 @@ export class FieldApi< batch(() => { const validateFieldFn = ( - field: FieldApi, + field: AnyFieldApi, validateObj: SyncValidator, ) => { const errorMapKey = getErrorMapKey(validateObj.cause) @@ -850,7 +1241,16 @@ export class FieldApi< validateAsync = async ( cause: ValidationCause, formValidationResultPromise: Promise< - FieldsErrorMapFromValidator + FieldsErrorMapFromValidator< + TParentData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > >, ) => { const validates = getAsyncValidatorArray(cause, this.options) @@ -868,7 +1268,29 @@ export class FieldApi< return acc.concat(fieldValidates as never) }, [] as Array< - AsyncValidator & { field: FieldApi } + AsyncValidator & { + field: FieldApi< + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any, + any + > + } >, ) @@ -888,7 +1310,7 @@ export class FieldApi< const linkedPromises: Promise[] = [] const validateFieldAsyncFn = ( - field: FieldApi, + field: AnyFieldApi, validateObj: AsyncValidator, promises: Promise[], ) => { @@ -1009,7 +1431,7 @@ export class FieldApi< // No error? Attempt async validation const formValidationResultPromise = this.form.validateAsync(cause) - return this.validateAsync(cause, formValidationResultPromise) + return this.validateAsync(cause, formValidationResultPromise as never) } /** @@ -1043,13 +1465,16 @@ export class FieldApi< * Updates the field's errorMap */ setErrorMap(errorMap: ValidationErrorMap) { - this.setMeta((prev) => ({ - ...prev, - errorMap: { - ...prev.errorMap, - ...errorMap, - }, - })) + this.setMeta( + (prev) => + ({ + ...prev, + errorMap: { + ...prev.errorMap, + ...errorMap, + }, + }) as never, + ) } } diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 0065ad22a..bbab0ff1b 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -5,6 +5,7 @@ import { getAsyncValidatorArray, getBy, getSyncValidatorArray, + isFormValidationError, isNonEmptyArray, setBy, } from './utils' @@ -12,11 +13,10 @@ import { isStandardSchemaValidator, standardSchemaValidator, } from './standardSchemaValidator' -import type { StandardSchemaV1 } from './standardSchemaValidator' -import type { FieldApi, FieldMeta, FieldMetaBase } from './FieldApi' import type { FormValidationError, FormValidationErrorMap, + SpecialFormValidationError, UpdateMetaOptions, ValidationCause, ValidationError, @@ -25,20 +25,55 @@ import type { ValidationSource, Validator, } from './types' +import type { StandardSchemaV1 } from './standardSchemaValidator' +import type { FieldApi, FieldMeta, FieldMetaBase } from './FieldApi' import type { DeepKeys, DeepValue } from './util-types' import type { Updater } from './utils' -export type FieldsErrorMapFromValidator = Partial< - Record, ValidationErrorMap> +export type FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, +> = Partial< + Record< + DeepKeys, + ValidationErrorMap< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + > > export type FormValidateFn< TFormData, TFormValidator extends Validator | undefined = undefined, + TReturnType = unknown, > = (props: { value: TFormData - formApi: FormApi -}) => FormValidationError + formApi: FormApi< + TFormData, + TFormValidator, + // This is technically an edge-type; which we try to keep non-`any`, but in this case + // It's referring to an inaccessible type from the field validate function inner types, so it's not a big deal + any, + any, + any, + any, + any, + any, + any + > +}) => TReturnType /** * @private @@ -46,11 +81,12 @@ export type FormValidateFn< export type FormValidateOrFn< TFormData, TFormValidator extends Validator | undefined = undefined, + TReturnType = unknown, > = TFormValidator extends Validator - ? TFN | FormValidateFn + ? TFN | FormValidateFn : - | FormValidateFn + | FormValidateFn | StandardSchemaV1 /** @@ -59,11 +95,24 @@ export type FormValidateOrFn< export type FormValidateAsyncFn< TFormData, TFormValidator extends Validator | undefined = undefined, + TReturnType = unknown, > = (props: { value: TFormData - formApi: FormApi + formApi: FormApi< + TFormData, + TFormValidator, + // This is technically an edge-type; which we try to keep non-`any`, but in this case + // It's referring to an inaccessible type from the field validate function inner types, so it's not a big deal + any, + any, + any, + any, + any, + any, + any + > signal: AbortSignal -}) => FormValidationError | Promise> +}) => TReturnType | Promise export type FormValidator = { validate(options: { value: TType }, fn: TFn): ValidationError @@ -86,29 +135,41 @@ type ValidationPromiseResult = export type FormAsyncValidateOrFn< TFormData, TFormValidator extends Validator | undefined = undefined, + TReturnType = undefined, > = TFormValidator extends Validator - ? FFN | FormValidateAsyncFn + ? FFN | FormValidateAsyncFn : - | FormValidateAsyncFn + | FormValidateAsyncFn | StandardSchemaV1 export interface FormValidators< TFormData, TFormValidator extends Validator | undefined = undefined, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, > { /** * Optional function that fires as soon as the component mounts. */ - onMount?: FormValidateOrFn + onMount?: FormValidateOrFn /** * Optional function that checks the validity of your data whenever a value changes */ - onChange?: FormValidateOrFn + onChange?: FormValidateOrFn /** * Optional onChange asynchronous counterpart to onChange. Useful for more complex validation logic that might involve server requests. */ - onChangeAsync?: FormAsyncValidateOrFn + onChangeAsync?: FormAsyncValidateOrFn< + TFormData, + TFormValidator, + TOnChangeAsyncReturn + > /** * The default time in milliseconds that if set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds. */ @@ -116,17 +177,25 @@ export interface FormValidators< /** * Optional function that validates the form data when a field loses focus, returns a `FormValidationError` */ - onBlur?: FormValidateOrFn + onBlur?: FormValidateOrFn /** * Optional onBlur asynchronous validation method for when a field loses focus returns a ` FormValidationError` or a promise of `Promise` */ - onBlurAsync?: FormAsyncValidateOrFn + onBlurAsync?: FormAsyncValidateOrFn< + TFormData, + TFormValidator, + TOnBlurAsyncReturn + > /** * The default time in milliseconds that if set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds. */ onBlurAsyncDebounceMs?: number - onSubmit?: FormValidateOrFn - onSubmitAsync?: FormAsyncValidateOrFn + onSubmit?: FormValidateOrFn + onSubmitAsync?: FormAsyncValidateOrFn< + TFormData, + TFormValidator, + TOnSubmitAsyncReturn + > } /** @@ -135,10 +204,40 @@ export interface FormValidators< export interface FormTransform< TFormData, TFormValidator extends Validator | undefined = undefined, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, > { fn: ( - formBase: FormApi, - ) => FormApi + formBase: FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >, + ) => FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > deps: unknown[] } @@ -148,6 +247,14 @@ export interface FormTransform< export interface FormOptions< TFormData, TFormValidator extends Validator | undefined = undefined, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, > { /** * Set initial values for your form. @@ -156,7 +263,19 @@ export interface FormOptions< /** * The default state for the form. */ - defaultState?: Partial> + defaultState?: Partial< + FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + > /** * If true, always run async validation, even when sync validation has produced an error. Defaults to undefined. */ @@ -172,22 +291,65 @@ export interface FormOptions< /** * A list of validators to pass to the form */ - validators?: FormValidators + validators?: FormValidators< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > /** * A function to be called when the form is submitted, what should happen once the user submits a valid form returns `any` or a promise `Promise` */ onSubmit?: (props: { value: TFormData - formApi: FormApi + formApi: FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > }) => any | Promise /** * Specify an action for scenarios where the user tries to submit an invalid form. */ onSubmitInvalid?: (props: { value: TFormData - formApi: FormApi + formApi: FormApi< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > }) => void - transform?: FormTransform + transform?: FormTransform< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > } /** @@ -225,7 +387,17 @@ export type FieldInfo< /** * An object representing the current state of the form. */ -export type BaseFormState = { +export type BaseFormState< + TFormData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, +> = { /** * The current values of the form fields. */ @@ -233,7 +405,16 @@ export type BaseFormState = { /** * The error map for the form itself. */ - errorMap: FormValidationErrorMap + errorMap: FormValidationErrorMap< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > /** * An internal mechanism used for keeping track of validation logic in a form. */ @@ -269,7 +450,17 @@ export type BaseFormState = { submissionAttempts: number } -export type DerivedFormState = { +export type DerivedFormState< + TFormData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, +> = { /** * A boolean indicating if the form is currently validating. */ @@ -281,7 +472,16 @@ export type DerivedFormState = { /** * The error array for the form itself. */ - errors: ValidationError[] + errors: Array< + | TOnMountReturn + | TOnChangeReturn + | TOnChangeAsyncReturn + | TOnBlurReturn + | TOnBlurAsyncReturn + | TOnSubmitReturn + | TOnSubmitAsyncReturn + | TOnServerReturn + > /** * A boolean indicating if any of the form fields are currently validating. */ @@ -320,12 +520,74 @@ export type DerivedFormState = { fieldMeta: Record, FieldMeta> } -export type FormState = BaseFormState & - DerivedFormState - -function getDefaultFormState( - defaultState: Partial>, -): BaseFormState { +export type FormState< + TFormData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, +> = BaseFormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn +> & + DerivedFormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + +function getDefaultFormState< + TFormData, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, +>( + defaultState: Partial< + FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + >, +): BaseFormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn +> { return { values: defaultState.values ?? ({} as never), errorMap: defaultState.errorMap ?? {}, @@ -344,11 +606,23 @@ function getDefaultFormState( } } -const isFormValidationError = ( - error: unknown, -): error is FormValidationError => { - return typeof error === 'object' -} +/** + * @public + * + * A type representing the Form API with all generics set to `any` for convenience. + */ +export type AnyFormApi = FormApi< + any, + any, + any, + any, + any, + any, + any, + any, + any, + any +> /** * A class representing the Form API. It handles the logic and interactions with the form state. @@ -360,14 +634,57 @@ const isFormValidationError = ( export class FormApi< TFormData, TFormValidator extends Validator | undefined = undefined, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TOnServerReturn = undefined, > { /** * The options for the form. */ - options: FormOptions = {} - baseStore!: Store> + options: FormOptions< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > = {} + baseStore!: Store< + BaseFormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + > fieldMetaDerived!: Derived, FieldMeta>> - store!: Derived> + store!: Derived< + FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + > /** * A record of field information for each field in the form. */ @@ -386,7 +703,20 @@ export class FormApi< /** * Constructs a new `FormApi` instance with the given form options. */ - constructor(opts?: FormOptions) { + constructor( + opts?: FormOptions< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >, + ) { this.baseStore = new Store( getDefaultFormState({ ...(opts?.defaultState as any), @@ -404,7 +734,16 @@ export class FormApi< const prevBaseStore = prevDepVals?.[0] const currBaseStore = currDepVals[0] - const fieldMeta = {} as FormState['fieldMeta'] + const fieldMeta = {} as FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + >['fieldMeta'] for (const fieldName of Object.keys( currBaseStore.fieldMetaBase, ) as Array) { @@ -423,8 +762,8 @@ export class FormApi< if (!prevBaseVal || currBaseVal.errorMap !== prevBaseVal.errorMap) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition fieldErrors = Object.values(currBaseVal.errorMap ?? {}).filter( - (val: unknown) => val !== undefined, - ) + (val) => val !== undefined, + ) as never } // As a primitive, we don't need to aggressively persist the same referencial value for performance reasons @@ -454,7 +793,19 @@ export class FormApi< this.store = new Derived({ deps: [this.baseStore, this.fieldMetaDerived], fn: ({ prevDepVals, currDepVals, prevVal: _prevVal }) => { - const prevVal = _prevVal as FormState | undefined + const prevVal = _prevVal as + | FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > + | undefined const prevBaseStore = prevDepVals?.[0] const currBaseStore = currDepVals[0] @@ -499,21 +850,26 @@ export class FormApi< !prevBaseStore || currBaseStore.errorMap !== prevBaseStore.errorMap ) { - errors = Object.values(currBaseStore.errorMap).reduce( - (prev, curr) => { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (curr === undefined) return prev - if (typeof curr === 'string') { - prev.push(curr) - return prev - } else if (curr && isFormValidationError(curr)) { - prev.push(curr.form) - return prev - } + errors = Object.values(currBaseStore.errorMap).reduce< + Array< + | TOnMountReturn + | TOnChangeReturn + | TOnChangeAsyncReturn + | TOnBlurReturn + | TOnBlurAsyncReturn + | TOnSubmitReturn + | TOnSubmitAsyncReturn + | TOnServerReturn + > + >((prev, curr) => { + if (curr === undefined) return prev + if (curr && isFormValidationError(curr)) { + prev.push(curr.form as never) return prev - }, - [] as ValidationError[], - ) + } + prev.push(curr as never) + return prev + }, []) } const isFormValid = errors.length === 0 @@ -546,7 +902,17 @@ export class FormApi< isBlurred, isPristine, isDirty, - } as FormState + } as FormState< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + > // Only run transform if state has shallowly changed - IE how React.useEffect works const transformArray = this.options.transform?.deps ?? [] @@ -575,14 +941,15 @@ export class FormApi< runValidator< TValue extends { value: TFormData - formApi: FormApi + formApi: FormApi validationSource: ValidationSource }, TType extends 'validate' | 'validateAsync', + TReturnType = unknown, >(props: { validate: TType extends 'validate' - ? FormValidateOrFn - : FormAsyncValidateOrFn + ? FormValidateOrFn + : FormAsyncValidateOrFn value: TValue type: TType }): ReturnType>[TType]> { @@ -621,7 +988,20 @@ export class FormApi< /** * Updates the form options and form state. */ - update = (options?: FormOptions) => { + update = ( + options?: FormOptions< + TFormData, + TFormValidator, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TOnServerReturn + >, + ) => { if (!options) return const oldOptions = this.options @@ -783,12 +1163,30 @@ export class FormApi< cause: ValidationCause, ): { hasErrored: boolean - fieldsErrorMap: FieldsErrorMapFromValidator + fieldsErrorMap: FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > } => { const validates = getSyncValidatorArray(cause, this.options) let hasErrored = false as boolean - const fieldsErrorMap: FieldsErrorMapFromValidator = {} + const fieldsErrorMap: FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > = {} batch(() => { for (const validateObj of validates) { @@ -874,7 +1272,18 @@ export class FormApi< */ validateAsync = async ( cause: ValidationCause, - ): Promise> => { + ): Promise< + FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + > => { const validates = getAsyncValidatorArray(cause, this.options) if (!this.state.isFormValidating) { @@ -973,7 +1382,16 @@ export class FormApi< let results: ValidationPromiseResult[] = [] - const fieldsErrorMap: FieldsErrorMapFromValidator = {} + const fieldsErrorMap: FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > = {} if (promises.length) { results = await Promise.all(promises) for (const fieldValidationResult of results) { @@ -1009,8 +1427,28 @@ export class FormApi< validate = ( cause: ValidationCause, ): - | FieldsErrorMapFromValidator - | Promise> => { + | FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + | Promise< + FieldsErrorMapFromValidator< + TFormData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + > + > => { // Attempt to sync validate first const { hasErrored, fieldsErrorMap } = this.validateSync(cause) @@ -1121,7 +1559,7 @@ export class FormApi< */ setFieldMeta = >( field: TField, - updater: Updater, + updater: Updater>, ) => { this.baseStore.setState((prev) => { return { @@ -1365,14 +1803,27 @@ export class FormApi< /** * Updates the form's errorMap */ - setErrorMap(errorMap: ValidationErrorMap) { - this.baseStore.setState((prev) => ({ - ...prev, - errorMap: { - ...prev.errorMap, - ...errorMap, - }, - })) + setErrorMap( + errorMap: ValidationErrorMap< + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn + >, + ) { + this.baseStore.setState( + (prev) => + ({ + ...prev, + errorMap: { + ...prev.errorMap, + ...errorMap, + }, + }) as never, + ) } } @@ -1381,16 +1832,12 @@ function normalizeError(rawError?: FormValidationError): { fieldErrors?: Partial, ValidationError>> } { if (rawError) { - if (typeof rawError === 'object') { + if (isFormValidationError(rawError)) { const formError = normalizeError(rawError.form).formError const fieldErrors = rawError.fields return { formError, fieldErrors } as never } - if (typeof rawError !== 'string') { - return { formError: 'Invalid Form Values' } - } - return { formError: rawError } } diff --git a/packages/form-core/src/mergeForm.ts b/packages/form-core/src/mergeForm.ts index 992301951..6d5a364f9 100644 --- a/packages/form-core/src/mergeForm.ts +++ b/packages/form-core/src/mergeForm.ts @@ -37,8 +37,32 @@ export function mergeForm< TFormData, TFormValidator extends Validator | undefined = undefined, >( - baseForm: FormApi, NoInfer>, - state: Partial['state']>, + baseForm: FormApi< + NoInfer, + NoInfer, + any, + any, + any, + any, + any, + any, + any, + any + >, + state: Partial< + FormApi< + TFormData, + TFormValidator, + any, + any, + any, + any, + any, + any, + any, + any + >['state'] + >, ) { mutateMergeDeep(baseForm.state, state) return baseForm diff --git a/packages/form-core/src/types.ts b/packages/form-core/src/types.ts index cff62ae7c..63ff376f9 100644 --- a/packages/form-core/src/types.ts +++ b/packages/form-core/src/types.ts @@ -1,6 +1,6 @@ import type { DeepKeys } from './util-types' -export type ValidationError = undefined | false | null | string +export type ValidationError = unknown export type ValidationSource = 'form' | 'field' @@ -8,15 +8,15 @@ export type ValidationSource = 'form' | 'field' * If/when TypeScript supports higher-kinded types, this should not be `unknown` anymore * @private */ -export type Validator = () => { +export type Validator = () => { validate( options: { value: Type; validationSource: ValidationSource }, fn: Fn, - ): ValidationError | FormValidationError + ): TReturnType validateAsync( options: { value: Type; validationSource: ValidationSource }, fn: Fn, - ): Promise> + ): Promise } /** @@ -41,17 +41,47 @@ export type ValidationErrorMapKeys = `on${Capitalize}` /** * @private */ -export type ValidationErrorMap = { - [K in ValidationErrorMapKeys]?: ValidationError +export type ValidationErrorMap< + TOnMountReturn = unknown, + TOnChangeReturn = unknown, + TOnChangeAsyncReturn = unknown, + TOnBlurReturn = unknown, + TOnBlurAsyncReturn = unknown, + TOnSubmitReturn = unknown, + TOnSubmitAsyncReturn = unknown, + TOnServerReturn = unknown, +> = { + onMount?: TOnMountReturn + onChange?: TOnChangeReturn | TOnChangeAsyncReturn + onBlur?: TOnBlurReturn | TOnBlurAsyncReturn + onSubmit?: TOnSubmitReturn | TOnSubmitAsyncReturn + onServer?: TOnServerReturn } /** * @private */ -export type FormValidationErrorMap = { - [K in ValidationErrorMapKeys]?: ValidationError | FormValidationError +export type FormValidationErrorMap< + TOnMountReturn = unknown, + TOnChangeReturn = unknown, + TOnChangeAsyncReturn = unknown, + TOnBlurReturn = unknown, + TOnBlurAsyncReturn = unknown, + TOnSubmitReturn = unknown, + TOnSubmitAsyncReturn = unknown, + TOnServerReturn = unknown, +> = { + onMount?: TOnMountReturn + onChange?: TOnChangeReturn | TOnChangeAsyncReturn + onBlur?: TOnBlurReturn | TOnBlurAsyncReturn + onSubmit?: TOnSubmitReturn | TOnSubmitAsyncReturn + onServer?: TOnServerReturn } +export type FormValidationError = + | ValidationError + | SpecialFormValidationError + /** * @private * @@ -65,12 +95,10 @@ export type FormValidationErrorMap = { * } * ```` */ -export type FormValidationError = - | ValidationError - | { - form?: ValidationError - fields: Partial, ValidationError>> - } +export type SpecialFormValidationError = { + form?: ValidationError + fields: Partial, ValidationError>> +} /** * @private diff --git a/packages/form-core/src/utils.ts b/packages/form-core/src/utils.ts index dd0aef3b1..a8455b090 100644 --- a/packages/form-core/src/utils.ts +++ b/packages/form-core/src/utils.ts @@ -1,4 +1,4 @@ -import type { ValidationCause } from './types' +import type { SpecialFormValidationError, ValidationCause } from './types' import type { FormValidators } from './FormApi' import type { FieldValidators } from './FieldApi' @@ -324,3 +324,9 @@ export function getSyncValidatorArray( return [changeValidator, serverValidator] as never } } + +export const isFormValidationError = ( + error: unknown, +): error is SpecialFormValidationError => { + return !!error && typeof error === 'object' && 'fields' in error +} diff --git a/packages/form-core/tests/FieldApi.spec.ts b/packages/form-core/tests/FieldApi.spec.ts index 157bda920..97886eded 100644 --- a/packages/form-core/tests/FieldApi.spec.ts +++ b/packages/form-core/tests/FieldApi.spec.ts @@ -1753,7 +1753,7 @@ describe('field api', () => { defaultMeta: { errorMap: { onChange: 'THERE IS AN ERROR', - }, + } as never, }, }) diff --git a/packages/form-core/tests/FieldApi.test-d.ts b/packages/form-core/tests/FieldApi.test-d.ts index 92ad5cb20..86107971e 100644 --- a/packages/form-core/tests/FieldApi.test-d.ts +++ b/packages/form-core/tests/FieldApi.test-d.ts @@ -146,3 +146,91 @@ it('should type an array sub-field properly', () => { assertType(field.state.value) }) + +it('should have the correct types returned from form validators', () => { + const form = new FormApi({ + defaultValues: { + name: 'test', + }, + validators: { + onChange: () => { + return '123' as const + }, + }, + } as const) + + assertType<'123' | undefined>(form.state.errorMap.onChange) +}) + +it('should have the correct types returned from form validators even when both onChange and onChangeAsync are present', () => { + const form = new FormApi({ + defaultValues: { + name: 'test', + }, + validators: { + onChange: () => { + return '123' as const + }, + onChangeAsync: async () => { + return '123' as const + }, + }, + } as const) + + assertType<'123' | undefined>(form.state.errorMap.onChange) +}) + +it('should have the correct types returned from field validators', () => { + const form = new FormApi({ + defaultValues: { + name: 'test', + }, + } as const) + + const field = new FieldApi({ + form, + name: 'name', + validators: { + onChange: () => { + return '123' as const + }, + }, + }) + + assertType<'123' | undefined>(field.state.meta.errorMap.onChange) +}) + +it('should have the correct types returned from field validators in array', () => { + const form = new FormApi({ + defaultValues: { + name: 'test', + }, + } as const) + + const field = new FieldApi({ + form, + name: 'name', + validators: { + onChange: () => { + return '123' as const + }, + }, + }) + + assertType>(field.state.meta.errors) +}) + +it('should have the correct types returned from form validators in array', () => { + const form = new FormApi({ + defaultValues: { + name: 'test', + }, + validators: { + onChange: () => { + return '123' as const + }, + }, + } as const) + + assertType>(form.state.errors) +}) diff --git a/packages/form-core/tests/FormApi.spec.ts b/packages/form-core/tests/FormApi.spec.ts index 1a6570981..afc1ea7ff 100644 --- a/packages/form-core/tests/FormApi.spec.ts +++ b/packages/form-core/tests/FormApi.spec.ts @@ -1573,7 +1573,7 @@ describe('form api', () => { form.mount() form.setErrorMap({ onChange: "name can't be Josh", - }) + } as never) expect(form.state.errorMap.onChange).toEqual("name can't be Josh") }) @@ -1585,11 +1585,11 @@ describe('form api', () => { form.mount() form.setErrorMap({ onChange: "name can't be Josh", - }) + } as never) expect(form.state.errorMap.onChange).toEqual("name can't be Josh") form.setErrorMap({ onBlur: 'name must begin with uppercase', - }) + } as never) expect(form.state.errorMap.onChange).toEqual("name can't be Josh") expect(form.state.errorMap.onBlur).toEqual('name must begin with uppercase') }) @@ -1602,11 +1602,11 @@ describe('form api', () => { form.mount() form.setErrorMap({ onChange: "name can't be Josh", - }) + } as never) expect(form.state.errorMap.onChange).toEqual("name can't be Josh") form.setErrorMap({ onChange: 'other validation error', - }) + } as never) expect(form.state.errorMap.onChange).toEqual('other validation error') }) @@ -1976,7 +1976,7 @@ describe('form api', () => { employees: Partial[] } - const form = new FormApi({ + const form = new FormApi({ validators: { onSubmit: ({ value }) => { const fieldWithErrorIndex = value.employees.findIndex( @@ -1994,6 +1994,7 @@ describe('form api', () => { return null }, }, + defaultValues: {} as Form, }) form.mount() const field = new FieldApi({ diff --git a/packages/lit-form/src/tanstack-form-controller.ts b/packages/lit-form/src/tanstack-form-controller.ts index f248007b2..ac05907a2 100644 --- a/packages/lit-form/src/tanstack-form-controller.ts +++ b/packages/lit-form/src/tanstack-form-controller.ts @@ -22,13 +22,43 @@ type renderCallback< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > = ( fieldOptions: FieldApi< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) => unknown @@ -42,21 +72,69 @@ type fieldDirectiveType< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > = ( - form: FormApi, + form: FormApi< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + >, options: FieldOptions< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn >, render: renderCallback< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) => { values: { @@ -66,14 +144,36 @@ type fieldDirectiveType< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn > render: renderCallback< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn > } } @@ -83,20 +183,61 @@ export class TanStackFormController< TFormValidator extends | Validator | undefined = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > implements ReactiveController { #host: ReactiveControllerHost #subscription?: () => void - api: FormApi + api: FormApi< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + > constructor( host: ReactiveControllerHost, - config?: FormOptions, + config?: FormOptions< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + >, ) { ;(this.#host = host).addController(this) - this.api = new FormApi(config) + this.api = new FormApi< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + >(config) } hostConnected() { @@ -115,20 +256,49 @@ export class TanStackFormController< | Validator, unknown> | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, >( fieldConfig: FieldOptions< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn >, render: renderCallback< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) { return ( @@ -137,7 +307,22 @@ export class TanStackFormController< TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn > )(this.api, fieldConfig, render) } @@ -153,9 +338,45 @@ class FieldDirective< | Validator | undefined = undefined, TData extends DeepValue = DeepValue, + TOnMountReturn = undefined, + TOnChangeReturn = undefined, + TOnChangeAsyncReturn = undefined, + TOnBlurReturn = undefined, + TOnBlurAsyncReturn = undefined, + TOnSubmitReturn = undefined, + TOnSubmitAsyncReturn = undefined, + TFormOnMountReturn = undefined, + TFormOnChangeReturn = undefined, + TFormOnChangeAsyncReturn = undefined, + TFormOnBlurReturn = undefined, + TFormOnBlurAsyncReturn = undefined, + TFormOnSubmitReturn = undefined, + TFormOnSubmitAsyncReturn = undefined, + TFormOnServerReturn = undefined, > extends AsyncDirective { #registered = false - #field?: FieldApi + #field?: FieldApi< + TParentData, + TName, + TFieldValidator, + TFormValidator, + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + > #unmount?: () => void constructor(partInfo: PartInfo) { @@ -198,20 +419,53 @@ class FieldDirective< } render( - _form: FormApi, + _form: FormApi< + TParentData, + TFormValidator, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn + >, _fieldConfig: FieldOptions< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn >, _renderCallback: renderCallback< TParentData, TName, TFieldValidator, TFormValidator, - TData + TData, + TOnMountReturn, + TOnChangeReturn, + TOnChangeAsyncReturn, + TOnBlurReturn, + TOnBlurAsyncReturn, + TOnSubmitReturn, + TOnSubmitAsyncReturn, + TFormOnMountReturn, + TFormOnChangeReturn, + TFormOnChangeAsyncReturn, + TFormOnBlurReturn, + TFormOnBlurAsyncReturn, + TFormOnSubmitReturn, + TFormOnSubmitAsyncReturn, + TFormOnServerReturn >, ) { if (this.#field) { diff --git a/packages/lit-form/tests/simple.ts b/packages/lit-form/tests/simple.ts index 25a36404f..5ff2eac39 100644 --- a/packages/lit-form/tests/simple.ts +++ b/packages/lit-form/tests/simple.ts @@ -42,7 +42,7 @@ export class TestForm extends LitElement { value.length < 3 ? 'Not long enough' : undefined, }, }, - (field: FieldApi) => { + (field) => { return html`
) => { + (field) => { return html`
` }, )} - ${this.form.field( - { name: `color` }, - (field: FieldApi) => { - return html`
- - + + + + +
` + })} + ${this.form.field({ name: `employed` }, (field) => { + return html` +
+ + - - - - -
` - }, - )} - ${this.form.field( - { name: `employed` }, - (field: FieldApi) => { - return html` -
- - -
- ${field.state.value - ? this.form.field( - { - name: `jobTitle`, - validators: { - onChange: ({ value }) => - value.length === 0 - ? 'Needs to have a job here' - : null, - }, - }, - (subField: FieldApi) => { - return html`
- - -
` + id="employed" + .type=${'checkbox'} + /> +
+ ${field.state.value + ? this.form.field( + { + name: `jobTitle`, + validators: { + onChange: ({ value }) => + value.length === 0 ? 'Needs to have a job here' : null, }, - ) - : ''} - ` - }, - )} + }, + (subField) => { + return html`
+ + +
` + }, + ) + : ''} + ` + })}