Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using superForms without a schema #367

Open
mpost opened this issue Feb 29, 2024 · 5 comments
Open

Allow using superForms without a schema #367

mpost opened this issue Feb 29, 2024 · 5 comments
Labels
enhancement New feature or request later May be worked on in the future.

Comments

@mpost
Copy link

mpost commented Feb 29, 2024

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?

@mpost mpost added the enhancement New feature or request label Feb 29, 2024
@ciscoheat
Copy link
Owner

You can use an empty object schema, or check this example: https://stackblitz.com/edit/sveltekit-superforms-list-actions

@mpost
Copy link
Author

mpost commented Mar 1, 2024

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.

@ciscoheat
Copy link
Owner

Doesn't z.object({}) work?

@mpost
Copy link
Author

mpost commented Mar 1, 2024

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).

@ciscoheat ciscoheat added the later May be worked on in the future. label Mar 4, 2024
@ciscoheat
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request later May be worked on in the future.
Projects
None yet
Development

No branches or pull requests

2 participants