Is there any way to disable validation with zod depending on a boolean variable?

signin_form

The image above is my signin form. I want to disable the validation functions of zod when clicking the signin with google or signin with github buttons except signin with credentials.

Is there any way to disable validation checks in zod when clicking those buttons?

N.B: I’m using react-hook-form.

My form schema is given below.

const formSchema = z.object({
  username: z.string().min(3).max(50),
  password: z.string().min(8).max(16)
});

export default function Page() {
  const form = useForm<z.infer<typeof formSchema>>({
    resolver: zodResolver(formSchema),
    defaultValues: {
      username: '',
      password: '',
    }
  });

  const onSubmit = (values: z.infer<typeof formSchema>) => {
    console.log(values);
  }

  return (
    <Authbox title="Signin">...</Authbox>
  );
}

  • please post a minimal reproducible example

    – 

  • Please provide enough code so others can better understand or reproduce the problem.

    – 
    Bot

Your SignIn with Google & SignIn with Github button should not have type as “submit”. In general, it does not make sense to have those buttons as part of your form.

Remove type=”submit” from two SignIn buttons and perform the operations using onClick event

Leave a Comment