Respect the form enctype
in progressive form enhancement example
#1936
Labels
examples
p2-nice-to-have
SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Milestone
Describe the problem
The form enhancement that ships in the demo ignores the
form[enctype]
and always posts the data as a multi-part form usingFormData
.While the
<form>
elements in the todos component do not explicitly define theenctype
, they inherit the default value ofapplication/x-www-form-urlencoded
.In other words, the behaviour differs depending on the context:
application/x-www-form-urlencoded
multipart/form-data
------WebKitFormBoundaryVXPDCeRyJsYB7s4v\nContent-Disposition: form-data; name="text"\n\nbuy some milk\n------WebKitFormBoundaryVXPDCeRyJsYB7s4v--
I think it would be preferable for the JS version to mirror the behaviour of native HTML form. Especially if this ends up becoming core functionality in sveltekit.
Describe the proposed solution
Modify the enhance action so that it mirrors browser behaviour.
According to MDN,
enctype
can be set on the form itself, but it can also be overridden by aformenctype
on the button which triggered the submit. The submit button is accessible on the SubmitEventFor example:
Notes
URLSearchParams
is not available in IEAlternatives considered
Documentation/comments so that developers are not caught off-guard.
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: