robertLichtnow / zod-formik-adapter

An adapter for zod object validation to Formik validation schema
https://www.npmjs.com/package/zod-formik-adapter
MIT License
160 stars 15 forks source link

feat: add toFormikValidate function #10

Closed amatiasq-heydoc closed 1 year ago

amatiasq-heydoc commented 2 years ago

This provides a new function toFormikValidate that will generate a validate function as Formik expects it.

This supports root union types with the caveat that the root error message will be passed as property "" of the error object:

const rootUnionErrorMessage = error[''];

This can be a work around for https://github.com/robertLichtnow/zod-formik-adapter/issues/2

CodeSandbox

Glazy commented 2 years ago

I made formik-validator-zod for this use case since it seems like zod-formik-adapter is no longer being maintained (?)

Give it a try and report an issue if you find any problems 👍

capaj commented 2 years ago

That looks gr8 Glazy! Does it support unions? If so, maybe you should mention in #2

Glazy commented 2 years ago

It does indeed @capaj 😄

https://github.com/Glazy/formik-validator-zod/blob/main/test/index.test.ts#L28-L37

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: