mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 09:50:33 +01:00
chore(Form): export FormValidationException in #ui/types (#47)
This commit is contained in:
@@ -4,6 +4,7 @@ import type { AppConfig } from '@nuxt/schema'
|
|||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/form'
|
import theme from '#build/ui/form'
|
||||||
import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, FormInjectedOptions, Form, FormErrorWithId } from '#ui/types/form'
|
import type { FormSchema, FormError, FormInputEvents, FormErrorEvent, FormSubmitEvent, FormEvent, FormInjectedOptions, Form, FormErrorWithId } from '#ui/types/form'
|
||||||
|
import { FormValidationException } from '#ui/types/form'
|
||||||
|
|
||||||
const appConfig = _appConfig as AppConfig & { ui: { form: Partial<typeof theme> } }
|
const appConfig = _appConfig as AppConfig & { ui: { form: Partial<typeof theme> } }
|
||||||
|
|
||||||
@@ -28,20 +29,6 @@ export interface FormEmits<T extends object> {
|
|||||||
export interface FormSlots {
|
export interface FormSlots {
|
||||||
default(): any
|
default(): any
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup generic="T extends object">
|
<script lang="ts" setup generic="T extends object">
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import type { ComputedRef, Ref } from 'vue'
|
import type { ComputedRef, Ref } from 'vue'
|
||||||
|
import type { ZodSchema } from 'zod'
|
||||||
|
import type { Schema as JoiSchema } from 'joi'
|
||||||
|
import type { ObjectSchema as YupObjectSchema } from 'yup'
|
||||||
|
import type { ObjectSchemaAsync as ValibotObjectSchema } from 'valibot'
|
||||||
|
|
||||||
export interface Form<T> {
|
export interface Form<T> {
|
||||||
validate (opts?: { name: string | string[], silent?: false, nested?: boolean }): Promise<T | false>
|
validate (opts?: { name: string | string[], silent?: false, nested?: boolean }): Promise<T | false>
|
||||||
@@ -10,7 +14,7 @@ export interface Form<T> {
|
|||||||
disabled: ComputedRef<boolean>
|
disabled: ComputedRef<boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FormSchema<T extends object> =
|
export type FormSchema<T extends Record<string, any>> =
|
||||||
| ZodSchema
|
| ZodSchema
|
||||||
| YupObjectSchema<T>
|
| YupObjectSchema<T>
|
||||||
| ValibotObjectSchema<T>
|
| ValibotObjectSchema<T>
|
||||||
@@ -67,8 +71,23 @@ export interface FormInjectedOptions {
|
|||||||
export interface FormFieldInjectedOptions<T> {
|
export interface FormFieldInjectedOptions<T> {
|
||||||
inputId: Ref<string | undefined>
|
inputId: Ref<string | undefined>
|
||||||
name: ComputedRef<string | undefined>
|
name: ComputedRef<string | undefined>
|
||||||
|
// @ts-ignore FIXME: TS doesn't like this
|
||||||
size: ComputedRef<T['size']>
|
size: ComputedRef<T['size']>
|
||||||
error: ComputedRef<string | boolean | undefined>
|
error: ComputedRef<string | boolean | undefined>
|
||||||
eagerValidation: ComputedRef<boolean | undefined>
|
eagerValidation: ComputedRef<boolean | undefined>
|
||||||
validateOnInputDelay: ComputedRef<number | undefined>
|
validateOnInputDelay: ComputedRef<number | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user