getConstraints
A helper that returns an object containing the validation attributes for each field by introspecting the valibot schema.
1import { getConstraints } from '@conform-to/valibot/future';
2
3const constraint = getConstraints(schema);#Parameters
schema
The value to introspect. If it's not a valid valibot schema, the function returns undefined.
#Examples
Passing constraints to useForm
Call getConstraints directly and pass the result to useForm to enable native HTML validation attributes (e.g. required, minLength, min, pattern) on your form fields:
1import { useForm } from '@conform-to/react/future';
2import { getConstraints } from '@conform-to/valibot/future';
3
4const { form, fields } = useForm({
5 constraint: getConstraints(schema),
6});Using with configureForms
Pass getConstraints to configureForms to automatically derive constraints for all forms without repeating it in every useForm call:
1import { configureForms } from '@conform-to/react/future';
2import { getConstraints } from '@conform-to/valibot/future';
3
4const { useForm } = configureForms({
5 getConstraints,
6});