Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parse params in zod validator #302

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nilscox
Copy link

@nilscox nilscox commented Aug 10, 2024

Hi,

Zod's parse function accepts some parameters, including an errorMap that is very useful to translate the error messages (see this page). I think it would make sense to allow forwarding these parameters from the validator to the parse function.

For example:

import { createForm } from '@felte/solid';
import { validateSchema } from '@felte/validator-zod';
import { z } from 'zod';

const schema = z.object({
  description: z.string().min(10),
});

const customErrorMap: z.ZodErrorMap = (error) => {
  // ... error translation logic ...
  return { message: '' };
};

function SomeComponent() {
  const { form } = createForm<z.infer<typeof schema>>({
    validate: validateSchema(schema, {
      errorMap: customErrorMap,
    }),
  });

  return <>...</>;
}

Copy link

vercel bot commented Aug 10, 2024

@nilscox is attempting to deploy a commit to the Pablo Alejandro Berganza Campos' projects Team on Vercel.

A member of the Team first needs to authorize it.

pablo-abc
pablo-abc previously approved these changes Oct 29, 2024
@pablo-abc
Copy link
Owner

Apologies for the delay! Would it be possible for you to update the README and/or the site along this PR?

I can do it afterwards if you don't have the time :)

@nilscox
Copy link
Author

nilscox commented Nov 5, 2024

I added a test and updated the README, I'll let you update the website as you see fit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants