Closed jogibs closed 2 years ago
Is it possible that you have two versions of react-hook-form in your yarn.lock? I've had this type of problem in the past due do useForm
addressing a different version of the form context than the one used by react-admin.
@fzaninotto Thanks for the quick answer!
Doesn't seem to be the case:
EDIT: Also, in /node_modules/react-hook-form/package.json, the version is 7.31.3
OK, then can you please build a reproduction based on the Simple Example Codesandbox?
https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple
@fzaninotto
Here we go: https://codesandbox.io/s/clever-danny-rl2uym?file=/src/posts/PostCreate.tsx
@jogibs I believe you need to use useFormContext
instead of useForm
.
As we can see on the example in the react-hook-form doc, useForm
is to declare a new form (which is done internally by react-admin), and useFormContext
is a helper to access the form context from within the form.
Here is a working example for your case: https://codesandbox.io/s/zealous-glade-t8cykp?file=/src/posts/PostCreate.tsx
Btw, linking two input fields is documented here: https://marmelab.com/react-admin/Inputs.html#linking-two-inputs
Thanks!
@jogibs I believe you need to use
useFormContext
instead ofuseForm
. As we can see on the example in the react-hook-form doc,useForm
is to declare a new form (which is done internally by react-admin), anduseFormContext
is a helper to access the form context from within the form.Here is a working example for your case: https://codesandbox.io/s/zealous-glade-t8cykp?file=/src/posts/PostCreate.tsx
Btw, linking two input fields is documented here: https://marmelab.com/react-admin/Inputs.html#linking-two-inputs
The link to the working example is not working, we would like to see how to use this.
Thanks!
@slax57
useForm
is to declare a new form (which is done internally by react-admin), anduseFormContext
is a helper to access the form context from within the form.
This is golden! Will print out on a tile and hang it in my office. Will save me more hours debugging my custom inputs and forms not playing ball with me.
Hey there! I'm having an issue with programmatically changing the value of an input, but none of the options seem to work. See below:
What you were expecting: The value should be applied to the input
What happened instead: The value isn't applied to the input
Related code:
Environment