-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Custom widget access to form Data #4192
Comments
Any ideas on this? I'm blocked from using this awesome library because of it |
The widget has access to the |
Thanks for the reply.
In this case, the field would “auto suggest” a value based on other fields
(which can also be corrected by the user if not correct).
Is that clear? Is there a way to achieve it?
…On Sat, 18 May 2024 at 5:38 am, Heath C ***@***.***> wrote:
The widget has access to the formData at its current level (in your
example the widget will get the value for name) via the value prop. Is
there a reason why you need access to all of the formData within a single
widget?
—
Reply to this email directly, view it on GitHub
<#4192 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUBXB72LVJNDJYNTNXQCALLZCZMDNAVCNFSM6AAAAABHRPO5VGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYGI2TSMZUGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@zzph I'm wondering if the "freezing" of the form you are seeing is a situation where your the state change causes a rerender infinite loop. Theoretically, you should be able to put anything into the |
Yes I've debugged, and it does seem like you're saying- it re-renders the entire component everytime 'formContext' changes. So this is an issue. Can you suggest a work around? |
Maybe you can process the formData on change in a way that you transform what you put into the formContext is only what you need to provide the |
I have a similar issue to this, I am trying to access the value of a property inside of a widget for a different property. I tried having a controlled state outside my form and the on change to update that, i could then pass this property thought like you suggest but this causes a re render loop :/ ( the onChange causes this). @zzph did you make any progress on this? |
What if you use a React context to store the form data rather than |
In order to make it work you need to pass const [formData, setFormData] = useState({});
return (
<Form
// ... other props ...
formData={formData}
onChange={({ formData }) => {
setFormData(formData);
}}
formContext={{ formData }}
/>
) |
Prerequisites
What theme are you using?
core
Version
5.x
Current Behavior
Inside my custom widget, it will not let me access the current formData. So I pass it into
formContext
but that breaks the form (nothing can be inputted).Expected Behavior
Inside my custom widget, I can access all the current values of the form
Steps To Reproduce
formData
to appear as a prop, but it does not, so I try passing it on formContext instead (as per issue hereI simplified my code as per below (CodeSandbox here):
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: