Example
Add zod validation and defaults to your instant schema by wrapping the field with theaddZod 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 theform.Field component.
field.state.meta.errorsis an array of zod errors that you can use to show custom error messages.getErrorMessageForFieldis a helper function that returns a concatenated string of all the error messages.