Calm motion: animations on this site only fade, with no movement
Form
Constraint-API form + field wiring
Use the browser's own validation (required, type="email", minlength, pattern) and let BlessField show the message. There is no schema, no rules object, nothing to import for the common case.
Basic
With a schema
How the wiring works
BlessFieldgives the first control inside it three things: theforid of the label,aria-invalidwhile it shows an error, andaria-describedby. The last one points at the description and the error. The description stays under an error, because it is usually what fixes it. Every Bless control takes them. You pass nothing. The slot props (id,error,describedby) remain for a plain<input>or a field with two controls.- A native validation message appears on the
invalidevent of the browser (a submit) or on blur. Blur counts only after the field has a value or the form is submitted, so tabbing through an empty form stays quiet. erroris for what the browser cannot know: the server said no. It wins over the native message while set. When the user edits, clear it.BlessFormsetsnovalidate, so the own bubble of the browser never shows. The field speaks instead. Only when everything is valid,@submitfires with(FormData, event). On a failed submit,@invalidfires with the form element after focus moves to the first invalid control. Reset clears the message of every field, and everyv-modelinside follows the reset values.#default="{ submitted }"tells you whether a person tried a submit. Use it for a summary line or a disabled button.
Check with a schema
The browser can check that a value is present, an email, or in a range. It cannot check a rule that spans fields, or a rule from your domain. For those rules, give schema a validator that follows Standard Schema. Zod, Valibot, and ArkType all follow it, and the library depends on none of them.
vue
<template>
<BlessForm :schema="schema" @submit="(data, event, value) => save(value)">…</BlessForm>
</template>
<script setup lang="ts">
import { z } from "zod";
const schema = z.object({
handle: z.string().regex(/^[a-z0-9_]+$/, "Use lowercase letters, digits, and _"),
age: z.coerce.number().min(13, "You must be 13 or older"),
});
</script>- The schema runs after the browser checks pass, on submit. It gets the form data as an object. A name that repeats, such as checkboxes, becomes an array.
- Form data is text. Use the coercion of your schema for numbers and dates (
z.coerce.number()).submithas a third argument,value, which is what the schema returned. Use it instead of the raw data. - A message appears in the
BlessFieldwhose control has the samenameas the first step of the issue path. GiveBlessFieldanameprop when the field holds several controls. An issue with no path, for example "Passwords do not match", goes toerrors[""]. Show it from the default slot:#default="{ errors }". - On a failed check,
invalidfires and focus moves to the first field with a message. When the person edits a field, its message goes away. Reset clears all of them. - The slot also has
pending, which is true while an async schema runs. Use it to disable the button. - A schema can be async.
submitwaits for it.
Usage
ts
import { BlessForm, BlessField } from "blessing-ui";API
BlessForm
Props
| Name | Type | Default | Description |
|---|---|---|---|
schema | BlessSchema<unknown> | — | A Standard Schema (Zod, Valibot, ArkType…) checked after the browser checks pass. Its messages show in the matching `BlessField`, by the `name` of the control. Form data is text, so use the schema's own coercion for numbers and dates. |
Events
| Name | Payload | Description |
|---|---|---|
submit | [data: FormData, event: SubmitEvent, value: unknown] | |
invalid | [form: HTMLFormElement] |
Slots
| Name | Scope | Description |
|---|---|---|
default | { submitted: boolean; errors: Record<string, string>; pending: boolean; } |
Exposed
| Name | Type | Description |
|---|---|---|
reset | () => void | |
el | HTMLFormElement |
BlessField
Props
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | |
hint | string | — | |
required | boolean | — | |
description | string | — | |
error | string | — | explicit error; otherwise read from the control's validity after submit/blur |
id | string | — | the id of the control; read once, when the field mounts. Default: a new id |
name | string | — | the `name` of the control, for the messages of a form `schema`. Default: the first named control inside. |
Slots
| Name | Scope | Description |
|---|---|---|
default | { id: string; error: string; describedby: string | undefined; } |