Form
A validated form.
Anatomy
Pair Form with Field:
<script setup>
import { Form } from '@shardsui/vue/form'
import { Field } from '@shardsui/vue/field'
</script>
<template>
<Form>
<Field.Root>
<Field.Label />
<Field.Control />
<Field.Error />
</Field.Root>
</Form>
</template>Examples
Validating from code
A template ref on the component exposes validate() — call it with a field name to run just that
one.
<script setup>
import { useTemplateRef } from 'vue'
import { Form } from '@shardsui/vue/form'
const form = useTemplateRef('form')
</script>
<template>
<Form ref="form">
<!-- fields -->
<button type="button" @click="form?.validate('email')">Check email</button>
</Form>
</template>API reference
Renders a <form> element. Submitting validates every field first; if one fails, the native submit
is cancelled and focus moves to the first invalid control, selecting its text when it is an
<input>.
errors is a one-way prop: the form copies it into its own state, and there is no update:errors
emit to bind to.
A template ref on the component exposes:
Form is generic over FormValues extends Record<string, unknown>, which defaults to
Record<string, unknown>. Annotate the parameter of the formSubmit handler to type the object
it receives.
Other standard <form> attributes (method, action, target, enctype) pass through.