mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-07 20:37:48 +00:00
fix: Cross-platform FormSubmitEvent via Register
This commit is contained in:
@@ -4,6 +4,16 @@ import type { DeepKeys, DeepValue, Updater } from './utils'
|
|||||||
import { functionalUpdate, getBy, setBy } from './utils'
|
import { functionalUpdate, getBy, setBy } from './utils'
|
||||||
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi'
|
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi'
|
||||||
|
|
||||||
|
export interface Register {
|
||||||
|
// FormSubmitEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FormSubmitEvent = Register extends {
|
||||||
|
FormSubmitEvent: infer E
|
||||||
|
}
|
||||||
|
? E
|
||||||
|
: Event
|
||||||
|
|
||||||
export type FormOptions<TData> = {
|
export type FormOptions<TData> = {
|
||||||
defaultValues?: TData
|
defaultValues?: TData
|
||||||
defaultState?: Partial<FormState<TData>>
|
defaultState?: Partial<FormState<TData>>
|
||||||
@@ -245,7 +255,7 @@ export class FormApi<TFormData> {
|
|||||||
return this.validationMeta.validationPromise
|
return this.validationMeta.validationPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = async (e: Event) => {
|
handleSubmit = async (e: FormSubmitEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import { createUseField, type UseField } from './useField'
|
|||||||
import { formContext } from './formContext'
|
import { formContext } from './formContext'
|
||||||
|
|
||||||
declare module '@tanstack/form-core' {
|
declare module '@tanstack/form-core' {
|
||||||
|
interface Register {
|
||||||
|
FormSubmitEvent: React.FormEvent<HTMLFormElement>
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
interface FormApi<TFormData> {
|
interface FormApi<TFormData> {
|
||||||
Form: FormComponent
|
Form: FormComponent
|
||||||
|
|||||||
Reference in New Issue
Block a user