✅ Painless Vue forms
This release is aimed at resolving #4421
useForm#defineComponentBinds
is now more strict and provides accurate typings for both modelValue
and update:modeValue
properties. Previously they were not exposed.Try the following example.
const { defineComponentBinds } = useForm({
validationSchema: toTypedSchema(yup.object({
date: yup.date().required(),
number: yup.number().required(),
string: yup.string().required(),
valueModel: yup.string().required(),
})),
});
const date = defineComponentBinds('date');
const number = defineComponentBinds('number');
const string = defineComponentBinds('string');
const valueModel = defineComponentBinds('valueModel');
validateOnModelUpdate
configuration #4451 #4467 (5231f439)This release updates valibot support to v0.13.0 and replaces the usage of deprecated API methods. #4414 (#4415)
You can now query fields meta state using isFieldTouched
, isFieldDirty
, and isFieldValid
helpers on useForm
.
const { isFieldDirty } = useForm();
isFieldDirty('myField') // true or false
// or compose it to be reactive:
const isFieldDirty = computed(() => isFieldDirty('myField'));
This release contains a couple of new features
Added composition functions to set field and form values, meta, and errors from their child components. The functions are:
useSetFieldValue
: sets a field's value.useSetFieldTouched
: sets a field's touched state.useSetFieldError
: sets a field's error message.useSetFormValues
: sets form values.useSetFormTouched
: sets multiple or all fields touched state.useSetFormErrors
: sets form error messages.Valibot is an impressive new schema validation library, mainly it offers Zod-like features at a much less bundle size due to its non-chainable API while still being easy to use and fully typed.
Because of this, vee-validate now supports it as a schema provider using the @vee-validate/valibot
package that exposes the same API function toTypedSchema
that you can use to get TypeScript support into your forms input and output values.
Quick example:
import { useForm } from 'vee-validate';
import { toTypedSchema } from '@vee-validate/valibot';
import { email, string, minLength, object } from 'valibot';
const { errors, values } = useForm({
validationSchema: toTypedSchema(
object({
email: string([minLength(1, 'Email is required'), email()]),
password: string([minLength(6, 'password too short')]),
}),
),
});
Refer to the docs for live examples and more information on typed schemas.