QuireKit
浏览组件

Form

统一管理表单草稿、校验、异步保存与重置,用字段配置快速搭建参数表单。

管理表单草稿、字段校验、提交与重置。手写字段用 QuireForm 与 QuireFormField,配置化表单用 QuireSchemaForm。

基础用法

initialValues 提供初值,FormField 用 name 注册字段。将插槽的 controlProps 完整绑定到控件;文本模型通过 String(value ?? '') 收窄类型。保存函数由 :on-submit 传入。

修改名称后保存。

校验与异步提交

required 检查非空,rules 返回 true 或错误文本。默认失焦校验,已显示错误的字段会在修改后重验;validateOn 可选 blur、change、submit。

Form 等待 onSubmit 返回的 Promise,并在校验和保存期间锁定草稿。isSubmitting 可用于禁用操作;失败提交默认聚焦首个可操作的错误字段。

文档信息

让协作者快速了解这份文档。

至少 4 个字符。
可选,简要说明文档内容。

当前为初始内容

尚未保存

success、invalidSubmit、error、reset 用于监听结果;异步保存请使用 :on-submit,不要用 @submit 代替。requiredMessage 定义空值提示;布尔字段必填时必须为 true。

加载记录与重置

initialValues 只捕获一次。加载另一条记录时调用 resetForm({ values: record }),同时替换草稿和重置基线。resetForm() 或 type="reset" 恢复当前基线,并清除错误、交互状态和提交次数。

与当前记录一致

提交期间 resetForm、setFieldValue、setValues 返回 false。需要回填保存结果时,等待提交结束后再调用;普通字段编辑使用插槽绑定即可。

配置化表单与条件字段

fields 接收字段和分组树:字段声明 name、label、control;分组声明 key、legend、children。内置控件有 input、textarea、number、select、checkbox、switch。

visible、disabled、readOnly 可读取当前 values。关闭下方“邮件通知”会隐藏邮箱并停止该字段的校验,再次开启时恢复草稿。

摘要内容
每次摘要保留 1–30 条进展。
完成通知
摘要生成后发送一封邮件。

设置摘要内容与通知方式。

number 模型保持字符串,以容纳清空和编辑中的输入;验证后再转换为业务数值。本地化数字需按所选格式解析。隐藏字段默认保留值,keepValueOnUnmount: false 可在卸载时清除;禁用字段跳过字段校验,只读字段继续校验。

跨字段校验与失败恢复

rules 支持 Promise,dependsOn 声明跨字段依赖。服务端字段错误用 setErrors 或 setFieldError 回填;请求失败抛出 Error,Form 保留草稿并显示 submitError。

下例保留 design 提交会提示名称占用;改为 design-team 后首次保存模拟请求失败,再点“重试保存”即可成功。admin 则展示异步保留名称校验。

3–20 位小写字母、数字或连字符。
成员规模

为空间选择一个好记的名称。

自定义控件与字段插槽

registry 注册已有控件,默认使用 modelValue / update:modelValue;其他模型通过 modelProp、updateEvent 和可选的值转换接入。

field:路径 插槽优先于注册控件。下例注册 Segmented,并通过动态插槽定制嵌套的 delivery.subject 字段;仍须保留 controlProps 的更新、状态和反馈关联。

[团队简报]
前缀会自动加到发送的邮件中。

按团队节奏发送项目简报。

使用其他模型时,可组合 value、setValue、handleBlur,无需再维护一份草稿。注册控件应支持禁用、只读、焦点和反馈关联。

后代组件访问表单

抽出的字段或操作组件可在 setup 中调用 useQuireForm(),复用祖先的表单状态。它必须实际位于 Form 后代中;不能在创建 Form 的同一个组件中提前调用。

vue

组合函数返回的状态是 ref,脚本中读取 .value;Form 的作用域插槽已经解包这些状态。

数据与原生表单

Form 的提交快照可能包含隐藏、禁用字段的保留值,由保存函数筛选业务数据;它不等同于原生 FormData。仅需要原生字段关联和浏览器约束校验时,使用 Field。

Form 自身渲染原生 form,不能嵌套;分组使用 Fieldset 或 SchemaForm 的分组节点。fields 是可信 TypeScript 配置,远程数据应先映射到应用允许的控件与规则。

API

QuireForm

QuireForm Props

Slots 内容位置

default

Fields and custom content with unwrapped form state.

actions

Optional save/reset actions sharing the same native form.

error

Replaces the request failure text inside the alert.

Events 组件事件

success
[values: QuireKitFormValues]
error
[error: unknown]
invalidSubmit
[errors: Record<string, string | undefined>]
reset
[]

公开实例成员

values

Read-only live values; use the setter methods to edit them.

QuireKitFormValues
errors

First error for each registered or server-reported path.

Partial<Record<string, string | undefined>>
meta

Aggregated dirty, touched, validity and pending state.

FormMeta<QuireKitFormValues>
isSubmitting

Lock spanning validation and application save.

boolean
isValidating

Whole-form validation activity.

boolean
submitCount

Number of accepted submit attempts since reset.

number
submitError

Recoverable request/validator failure message.

string | undefined
setFieldValue

Set a nested value using VeeValidate's path semantics.

(path: string, value: unknown, shouldValidate?: boolean | undefined) => boolean
setValues

Merge a set of values into the draft.

(values: QuireKitFormValues, shouldValidate?: boolean | undefined) => boolean
setErrors

Attach server errors without erasing the draft.

(fields: Partial<FlattenAndSetPathsType<QuireKitFormValues, string | string[] | undefined>>) => void
setFieldError

Set or clear a single field error.

(field: string, message: string | string[] | undefined) => void
setFieldTouched

Set interaction state for one path.

(field: string, isTouched: boolean) => void
validate

Validate the complete form.

() => Promise<FormValidationResult<QuireKitFormValues, QuireKitFormValues>>
validateField

Validate one path.

<TPath extends string>(field: TPath, opts?: Partial<ValidationOptions> | undefined) => Promise<ValidationResult<unknown>>
submit

Validate and await save; repeat calls during the lock are ignored.

(event?: Event | undefined) => Promise<void>
resetForm

Reset baseline and metadata; returns false while submitting.

(state?: Partial<FormState<QuireKitFormValues>> | undefined, options?: Partial<ResetFormOpts> | undefined) => boolean
focusFirstError

Focus the first available field error in DOM order.

() => Promise<void>
reportError

Surface an unexpected asynchronous failure and emit error.

(error: unknown) => void

QuireFormField

QuireFormField Props

Slots 内容位置

default

Render one input, binding controlProps or using the custom model actions.

meta

Short information or an action next to the label.

message

Replaces the current feedback text without removing its semantic container.

Events 组件事件

无自定义事件。

QuireSchemaForm

QuireSchemaForm Props

Slots 内容位置

default

Extra content rendered after generated fields.

actions

Explicit consumer-provided save/reset actions.

error

Optional replacement for request error feedback.

Events 组件事件

无自定义事件。

公开实例成员

form
{ readonly values: QuireKitFormValues; readonly errors: Partial<Record<string, string | undefined>>; readonly meta: FormMeta<QuireKitFormValues>; readonly isSubmitting: boolean; readonly isValidating: boolean; readonly submitCount: number; readonly submitError: string | undefined; readonly disabled: boolean; readonly readOnly: boolean; readonly validateOn: QuireKitFormValidateOn; readonly setFieldValue: (path: string, value: unknown, shouldValidate?: boolean | undefined) => boolean; readonly setValues: (values: QuireKitFormValues, shouldValidate?: boolean | undefined) => boolean; readonly setErrors: (fields: Partial<FlattenAndSetPathsType<QuireKitFormValues, string | string[] | undefined>>) => void; readonly setFieldError: (field: string, message: string | string[] | undefined) => void; readonly setFieldTouched: (field: string, isTouched: boolean) => void; readonly validate: () => Promise<FormValidationResult<QuireKitFormValues, QuireKitFormValues>>; readonly validateField: <TPath extends string>(field: TPath, opts?: Partial<ValidationOptions> | undefined) => Promise<ValidationResult<unknown>>; readonly submit: (event?: Event | undefined) => Promise<void>; readonly resetForm: (state?: Partial<FormState<QuireKitFormValues>> | undefined, options?: Partial<ResetFormOpts> | undefined) => boolean; readonly focusFirstError: () => Promise<void>; readonly reportError: (error: unknown) => void; } | undefined
submit
(event?: Event | undefined) => Promise<void>
resetForm
(state?: Partial<FormState<QuireKitFormValues>> | undefined, options?: Partial<ResetFormOpts> | undefined) => boolean