From 37abcc6a5b0a678be626673af5067956657a50d6 Mon Sep 17 00:00:00 2001 From: Tankosin Date: Fri, 30 May 2025 16:29:01 +0300 Subject: [PATCH] fix(Form): conditionally type form data via `transform` prop (#4188) Co-authored-by: Benjamin Canac --- src/runtime/components/Form.vue | 34 ++++++++++++++++----------------- src/runtime/types/form.ts | 16 +++++++++------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/runtime/components/Form.vue b/src/runtime/components/Form.vue index c5f4d5dc..a215c4a3 100644 --- a/src/runtime/components/Form.vue +++ b/src/runtime/components/Form.vue @@ -2,12 +2,12 @@ import type { DeepReadonly } from 'vue' import type { AppConfig } from '@nuxt/schema' import theme from '#build/ui/form' -import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, Form, FormErrorWithId, InferInput, InferOutput } from '../types/form' +import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, Form, FormErrorWithId, InferInput, InferOutput, FormData } from '../types/form' import type { ComponentConfig } from '../types/utils' type FormConfig = ComponentConfig -export interface FormProps { +export interface FormProps { id?: string | number /** Schema to validate the form state. Supports Standard Schema objects, Yup, Joi, and Superstructs. */ schema?: S @@ -35,7 +35,7 @@ export interface FormProps { * If true, schema transformations will be applied to the state on submit. * @defaultValue `true` */ - transform?: boolean + transform?: T /** * If true, this form will attach to its parent Form (if any) and validate at the same time. @@ -50,11 +50,11 @@ export interface FormProps { */ loadingAuto?: boolean class?: any - onSubmit?: ((event: FormSubmitEvent>) => void | Promise) | (() => void | Promise) + onSubmit?: ((event: FormSubmitEvent>) => void | Promise) | (() => void | Promise) } -export interface FormEmits { - (e: 'submit', payload: FormSubmitEvent>): void +export interface FormEmits { + (e: 'submit', payload: FormSubmitEvent>): void (e: 'error', payload: FormErrorEvent): void } @@ -63,7 +63,7 @@ export interface FormSlots { } -