sveltekit-superforms
sveltekit-superforms copied to clipboard
Allow using superForms without a schema
Running on the latest superForms v2.6.1
i want to make a POST request to delete an item. Therefore i only want to send the item id to delete. My thinking is to use superforms, along with its useful callbacks to perform that task. I do not need an extra schema but would be happy to use the form.id
from superforms to transfer the id.
However, creating a superValidated/superForm without schema does not seem to be supported. How would i approach such a scenario?
You can use an empty object schema, or check this example: https://stackblitz.com/edit/sveltekit-superforms-list-actions
Thanks for your answer. This is an interesting example. It has similar requirements to my use-case.
An observation: The "delete" buttons carry the value of the id
has defined in the schema. However, that is not required, since in the +page.server.ts
the line 28 could be exchanged for the following, using the form id instead of the schema id
.
const index = constellations.findIndex((s) => s.id.toString() == form.id);
This would render the schema itself not required.
Could you give an example on how to create an empty superValidate/superForm? I found that a ValidationAdapter
is required and there is no adapter which accepts an "empty" object or something similar to z.unkown()
(when using zod). Thanks.
Doesn't z.object({})
work?
Creating an empty zod object via superValidate(request, zod(z.object({})))
does work. It would be nice however, to not having to rely on a specific validator implementation to create a dummy validator. Eg.: superValidate(request)
.
The adapter is quite central to superValidate, so it'll take a bit of work, also to figure out defaults, so it'll have to be a future feature.