Skip to main content

Example

Add zod validation and defaults to your instant schema by wrapping the field with the addZod function. This example shows a few different zod examples. makeLinkRequired is a helper function that makes a link field required with a custom zod error message.
InstantDB uses number | string for dates, which is why we use z.number() for validation and a number value for the default.

Defaults

Using zod is optional! Without it, the form will automatically use a default zod validator depending on the instantdb type.

Showing errors

Error message values are passed to the UI components as a prop inside the form.Field component.
  • field.state.meta.errors is an array of zod errors that you can use to show custom error messages.
  • getErrorMessageForField is a helper function that returns a concatenated string of all the error messages.