mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 08:50:34 +01:00
feat(Form): nested form validation (#23)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
43
src/runtime/types/form.d.ts
vendored
43
src/runtime/types/form.d.ts
vendored
@@ -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>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user