feat(Form): nested form validation (#23)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Romain Hamel
2024-03-21 18:39:59 +01:00
committed by GitHub
parent f086f2662e
commit 167127861f
9 changed files with 604 additions and 144 deletions

View File

@@ -1,8 +1,7 @@
import type { ComputedRef, Ref } from 'vue'
export interface Form<T> {
validate (path?: string | string[], opts?: { silent?: true }): Promise<T | false>
validate (path?: string | string[], opts?: { silent?: false }): Promise<T | false>
validate (opts?: { name: string | string[], silent?: false, nested?: boolean }): Promise<T | false>
clear (path?: string): void
errors: Ref<FormError[]>
setErrors (errs: FormError[], path?: string): void
@@ -29,16 +28,43 @@ export interface FormErrorWithId extends FormError {
}
export type FormSubmitEvent<T> = SubmitEvent & { data: T }
export type FormErrorEvent = SubmitEvent & { errors: FormErrorWithId[] }
export type FormEventType = FormInputEvents | 'submit'
export type FormValidationError = {
errors: FormErrorWithId[]
childrens: FormValidationError[]
}
export interface FormEvent {
export type FormErrorEvent = SubmitEvent & FormValidationError
export type FormEventType = FormInputEvents
export type FormChildAttachEvent = {
type: 'attach'
formId: string | number
validate: Form<any>['validate']
}
export type FormChildDetachEvent = {
type: 'detach'
formId: string | number
}
export type FormInputEvent = {
type: FormEventType
name?: string
}
export interface InjectedFormFieldOptions<T> {
export type FormEvent =
| FormInputEvent
| FormChildAttachEvent
| FormChildDetachEvent
export interface FormInjectedOptions {
disabled?: ComputedRef<boolean>
validateOnInputDelay?: ComputedRef<number>
}
export interface FormFieldInjectedOptions<T> {
inputId: Ref<string | undefined>
name: ComputedRef<string | undefined>
size: ComputedRef<T['size']>
@@ -46,8 +72,3 @@ export interface InjectedFormFieldOptions<T> {
eagerValidation: ComputedRef<boolean | undefined>
validateOnInputDelay: ComputedRef<number | undefined>
}
export interface InjectedFormOptions {
disabled?: ComputedRef<boolean>
validateOnInputDelay?: ComputedRef<number>
}