Skip to content

Generic form error (not specific to a field) #290

Answered by codepunkt
codepunkt asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks a lot, @edmundhung!

Both examples didn't work like that exactly, but gave me enough hints to make them work

  • Example 1: Enable async and using value instead of submission.value:

    export async function action({ request }: ActionFunctionArgs) {
      const formData = await request.formData()
      const submission = parse(formData, {
        async: true,
        schema: schema.tranform(async (value, ctx) => {
          try {
            return await mutation(loginMutation, value)
          } catch (error) {
            ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Your form error message' });
            // create falsy `submission.value` so that it's returned to the component
            // as part of `json(submis…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@codepunkt
Comment options

Answer selected by edmundhung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants