diff --git a/playground/components/FormNestedExample.vue b/playground/components/FormNestedExample.vue new file mode 100644 index 00000000..c677d6b0 --- /dev/null +++ b/playground/components/FormNestedExample.vue @@ -0,0 +1,66 @@ + + + diff --git a/playground/components/FormNestedListExample.vue b/playground/components/FormNestedListExample.vue new file mode 100644 index 00000000..be9556c7 --- /dev/null +++ b/playground/components/FormNestedListExample.vue @@ -0,0 +1,85 @@ + + + diff --git a/playground/pages/form.vue b/playground/pages/form.vue index d91c304e..eb95d3b3 100644 --- a/playground/pages/form.vue +++ b/playground/pages/form.vue @@ -24,81 +24,88 @@ function onSubmit (event: FormSubmitEvent) { diff --git a/src/runtime/components/Form.vue b/src/runtime/components/Form.vue index 6ec27bd7..0427b41b 100644 --- a/src/runtime/components/Form.vue +++ b/src/runtime/components/Form.vue @@ -4,13 +4,14 @@ import type { AppConfig } from '@nuxt/schema' import _appConfig from '#build/app.config' import theme from '#build/ui/form' import { getYupErrors, isYupSchema, getValibotError, isValibotSchema, getZodErrors, isZodSchema, getJoiErrors, isJoiSchema } from '../utils/form' -import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, InjectedFormOptions, Form } from '../types/form' +import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, FormInjectedOptions, Form, FormErrorWithId } from '../types/form' const appConfig = _appConfig as AppConfig & { ui: { form: Partial } } const form = tv({ extend: tv(theme), ...(appConfig.ui?.form || {}) }) export interface FormProps { + id?: string | number schema?: FormSchema state: Partial validate?: (state: Partial) => Promise @@ -29,18 +30,24 @@ export interface FormSlots { default(): any } -export class FormException extends Error { - constructor (message: string) { - super(message) - this.message = message - Object.setPrototypeOf(this, FormException.prototype) +export class FormValidationException extends Error { + formId: string | number + errors: FormErrorWithId[] + childrens: FormValidationException[] + + constructor (formId: string | number, errors: FormErrorWithId[], childErrors: FormValidationException[]) { + super('Form validation exception') + this.formId = formId + this.errors = errors + this.childrens = childErrors + Object.setPrototypeOf(this, FormValidationException.prototype) } } diff --git a/src/runtime/components/FormField.vue b/src/runtime/components/FormField.vue index 5627aa19..dbb7f8e8 100644 --- a/src/runtime/components/FormField.vue +++ b/src/runtime/components/FormField.vue @@ -37,7 +37,7 @@ export interface FormFieldSlots {