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

Can't reset field #719

Open
benjamin-benoit opened this issue Oct 21, 2024 · 0 comments
Open

Can't reset field #719

benjamin-benoit opened this issue Oct 21, 2024 · 0 comments

Comments

@benjamin-benoit
Copy link

Describe the bug
Hello, I have an issue to reset a field on my react typescript project, I'm using zod and hook form.

To Reproduce
First I do my object:

const interventionSchema = z.object({
  thematiqueId: z.number().optional().nullable(),
  domaineId: z.number().optional().nullable(),
});

Next I do my useForm:

  const {
    register,
    handleSubmit,
    reset,
    setValue,
    watch,
    resetField,
  } = useForm<InterventionPost>({
    resolver: zodResolver(interventionSchema),
    defaultValues: {
      domaineId: undefined,
    },
  });

In my form I have on a Select:

          onValueChange={(value) => {
                        setValue("thematiqueId", Number(value));
                        reset({
                          domaineId: undefined,
                        });
                        resetField("domaineId");
                      }}

Expected behavior
On the logs, the value of domainId is not on undefined:

  useEffect(() => {
    console.log("Form Values:", watch());
  }, [watch()]);
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

No branches or pull requests

1 participant