using `useForm` in a `Show` action possible?
using
useForm
in a Show
action possible? basically i want my show screen to look like my edit screen with minimal effort, and by that, i mean just disabling all inputs, how can i achieve this?
My code looks like this
2 Replies
Hi @flankieflew. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible to use
useForm
in a Show
action, and you can achieve your goal of making the show screen look like the edit screen with minimal effort. Here's how you can modify your code to accomplish this:
1. Change the Show
component to Edit
:
2. Use the action
prop in useForm
to specify that it's a "show" action:
3. Remove the disabled
prop from individual form fields, as it's now handled globally.
Here's the modified version of your code:
This approach allows you to reuse your edit form for the show view with minimal changes. The useForm
hook will fetch the data for the record, and all inputs will be disabled.
For more information on the useForm
hook and its properties, you can refer to the following documentation:
useForm Properties (https://refine.dev/docs/packages/react-hook-form/use-form/#properties)
useForm Actions (https://refine.dev/docs/data/hooks/use-form/#action-)
These resources provide detailed information on how to use the useForm
hook in different scenarios, including the "show" action.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@343691288442306561> Kapa.ai is still learning and improving, please let me know how I did by reacting below.