Skip to content

RFC: Issue-186 #582

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

TweedChristian
Copy link

@TweedChristian TweedChristian commented Apr 3, 2025

Fixes 186.

Adds the server side parsing of nested data for progressive enhancement to be used in conjuction with dataType: 'json'. Inspired by this pattern.

<input type="text" name="author.firstName" />
<input type="text" name="author.books[0].title" />

The example page includes some patterns that would be standard for adding values to the nested form. Since this isn't as dynamic as a client parsing of the data, you'll need to be creative about how you update the data and name things.

Changes

  • Added an unflatten option to the superValidate call.
  • Adds a self-contained parseFlattenedData to formData.ts.
  • [TODO]: Add tests
  • [TODO]: Update withFiles to check nested data

Notes

This still needs more tests and I haven't thrown every schema at it (e.g., unions). In addition, I think I repeat the idea of traversing json-schema too often and I need to create some utilities. I wanted to get some eyes on this before I got too deep into a refactor pass.

Eventually, I'd like this to also support this pattern as well

<input type="text" name="author.books" value="[{title: 'IT'}, {title: 'Cujo'}]" />

Copy link

vercel bot commented Apr 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
superforms ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2025 2:07am

@TweedChristian TweedChristian changed the title Issue-186 RFC: Issue-186 Apr 3, 2025
@TweedChristian
Copy link
Author

Actually, the more I think about it, this would make sense as a v3 introduction since then we wouldn't have to maintain two form data parsing methods. We could assume that un-flattening the object access notation is now the default as a breaking change. I think we could also update the normal dataType: 'json' parser to include checking for disabled attributes since the form name would match.

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.

Send nested data in a plain form
1 participant