Automatically convert FormData to JSON
See original GitHub issueIs your feature request related to a problem? Please describe. Since svelte advocates progressive enhancement, I think an utility to automatically convert FormData to JSON can be really helpful to write forms that works w/o JavaScript.
The demo currently does it manually, but once the form becomes complex, the conversion can be cumbersome. e.g.,:
<input name="items[0].name" value="Shoe">
<input name="items[0].price" value="99">
<input name="items[1].name" value="Pants">
<input name="items[1].price" value="99">
Describe the solution you’d like
Svelte kit provides an utility that automatically converts FormData to JSON. However, since FormData erases type like number, a mapping between FormData and types is needed. One solution I can think of is that svelte kit allows specifying an attribute like svelte:type="number"
on form controls, and svelte kit would parse the types into a manifest keyed by form action, if it points to an endpoint, and the utility is only usable in the endpoint that uses the manifest to generate the corresponding JSON.
Describe alternatives you’ve considered
How important is this feature to you? Not very, since it’s manually convertible.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
oh wait, I think I misunderstood — you want a mechanism for converting the
ReadOnlyFormData
inside endpoints to JSON? That seems like something that ought to be done in userland, in thehandle
functionIn newer versions, we expose a
Request
object, and form data is generated withawait request.formData()
. Anything beyond that belongs in userland, so I’ll close this