getConstraints
A helper that returns an object containing the validation attributes for each field by introspecting the zod schema.
1import { getConstraints } from '@conform-to/zod/v3/future';
2// or
3import { getConstraints } from '@conform-to/zod/v4/future';
4
5const constraint = getConstraints(schema);#Parameters
schema
The value to introspect. If it's not a valid zod 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/zod/v3/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/zod/v3/future';
3
4const { useForm } = configureForms({
5 getConstraints,
6});