Field ​
A component that provides labeling and validation for form controls.
Field control props mapping ​
<HField
v-slot="{ fieldProps }"
>
<HTextInput v-bind="fieldProps" />
</HField>The fieldProps object provided by HField maps standard component props to the form state:
modelValue: The current value of the field.onUpdate:modelValue: Updates the field value.onBlur: Marks the field as touched and triggers validation (if mode is onBlur).name: The field name.id: A unique ID for accessibility.
Examples ​
Label position ​
By default, HField will follow the label-position prop of the parent HForm. You can override this behavior by passing the label-position prop to the HField component.
With children slot ​
Custom error message ​
The easiest way to customize error messages is directly within your Zod schema definition. vee-validate will pick these up and HField will display them automatically.
const schema = z.object({
email: z.string().email({ message: "Please provide a valid work email" })
})Async validation ​
You can perform asynchronous validation (e.g. checking if a username exists) using Zod's .refine() with an async function.
const schema = z.object({
username: z.string().refine(async (name) => {
const isTaken = await checkAvailability(name)
return !isTaken
}, { message: "Username is already taken" })
})The form's isValidating state will be true while the async check is pending.
API ​
Pass-through: <div> ​
What does this mean?
All props, events, and attrs that are not specified in the tables below will be passed to the element/component described above.