sveltekit-superforms icon indicating copy to clipboard operation
sveltekit-superforms copied to clipboard

RFC: Issue-186

Open TweedChristian opened this issue 7 months ago • 3 comments

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'}]" />

TweedChristian avatar Apr 03 '25 02:04 TweedChristian

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

vercel[bot] avatar Apr 03 '25 02:04 vercel[bot]

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.

TweedChristian avatar Apr 06 '25 15:04 TweedChristian

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

hasinoorit avatar Jul 03 '25 13:07 hasinoorit