Check out our talk at Remix Conf!

Transform values

In this example, we use different schemas for the form and the mutation, transforming the form values before calling the mutation.

const formSchema = z.object({
  firstName: z.string().min(1),
  email: z.string().min(1).email(),
})

const mutationSchema = formSchema.extend({
  country: z.enum(['BR', 'US']),
})

const mutation = makeDomainFunction(mutationSchema)(async (values) => values)

export const action: ActionFunction = async ({ request }) =>
  formAction({
    request,
    schema: formSchema,
    mutation,
    transformValues: (values) => ({ ...values, country: 'US' }),
  })

export default () => <Form schema={schema} />