sveltekit-superforms
sveltekit-superforms copied to clipboard
RFC: Issue-186
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
unflattenoption to thesuperValidatecall. - Adds a self-contained
parseFlattenedDatatoformData.ts. - [TODO]: Add tests
- [TODO]: Update
withFilesto 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'}]" />
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 |
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.
I was searching for this feature. eventually i ended up with creating my won library, May be this can help https://github.com/hasinoorit/formstruct