Virtual field #2232
-
Is there a way currently to mark a given field as virtual/transient? Let's say for instance "Accept terms" on a singup form. I would like this field to be part of the form (i.e. for validation) but I am not interested in sending this field to back end. I could obviously strip it off in the onSubmit method somewhere but maybe we could have an option of excluding it befor it is passed to |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Totally, https://react-hook-form.com/advanced-usage/#Workingwithvirtualizedlists you can register input at useEffect. |
Beta Was this translation helpful? Give feedback.
-
I don't see how this answer answers the question. It certainly shows that we can register a component in use effect, but it doesn't provide any information about how to remove the field when we submit. In the example provided, the code sandbox example (https://codesandbox.io/s/react-hook-form-controlled-mixed-with-uncontrolled-forked-c323j) does indeed show registering, but when we click submit the registered field is still submitted. This is not the behavior that OP asked about. |
Beta Was this translation helpful? Give feedback.
-
This discussion is really old and related to previous version of react-hook-form that might have different behavior than the latest version. You can use Working demo: https://codesandbox.io/s/react-hook-form-unregister-forked-pk39fj?file=/src/index.tsx |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip! |
Beta Was this translation helpful? Give feedback.
Totally, https://react-hook-form.com/advanced-usage/#Workingwithvirtualizedlists you can register input at useEffect.