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

Modifies useForm to handle nested data #1338

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from

Conversation

aviemet
Copy link

@aviemet aviemet commented Nov 12, 2022

In relation to this discussion , here's a proposal for using nested form data in the react package. This uses @sbc640964's suggestion to utilize lodash methods, which made sense to me since lodash was already a dependency.

This also adds a getData function which is essentially just an alias for the lodash get function. Purely a convenience method which will help to build custom form and input components.

Since part of the goal is to make the form hook more compatible with backend data, I also included a sanitizer which processes the data passed in. React doesn't like when a controlled input's value changes from null or undefined to a value, it wants empty inputs to be an empty string. Converting null and undefined values into empty strings allows us to directly pass in empty objects from our controllers, which mimics how one might build a form in a vanilla Rails project.

@Bosphoramus
Copy link

Bosphoramus commented Feb 7, 2023

Shouldnt JS native structuredClone be used instead of lodash deepClone?

Is this only for the React adapter? Would be useful in all adapters

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

Successfully merging this pull request may close these issues.

2 participants