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 = applySchema(mutationSchema)(async (values) => values)

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

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