ciscoheat / sveltekit-superforms

Making SvelteKit forms a pleasure to use!
https://superforms.rocks
MIT License
2.15k stars 65 forks source link

Svelte-only version of Superforms #321

Open ciscoheat opened 8 months ago

ciscoheat commented 8 months ago

I'm looking for ideas on how to separate the code to make a Svelte-only version of Superforms. It should share as much code as possible with the SK version, and there should be some convenient build tool to easily package two versions.

The SvelteKit imports that needs to be removed are:

import { navigating, page } from '$app/stores';
import { browser } from '$app/environment';
import { beforeNavigate, goto, invalidateAll } from '$app/navigation';
import { applyAction, enhance } from '$app/forms';

Thanks for any help!

FluffyDiscord commented 7 months ago

Svelte only version where we could connect it to our own backend would be amazing

philippone commented 7 months ago

I'm using a workaround in a much more complex setup (Svelte Web Comonents inside of an old AngularJs Project).

To be able to use superforms without sveltekit, I provide the missing functionality by using a vite/typescript alias, i.e. I implement the $app/*-interfaces inside of my application and overwrite the import $app/* via alias.

To support all superform functionality you have to provide a proper implementation of the interfaces (for instance link your application router to beforeNavigate) . I'm just fine with client side validation and did not implement all missing methods.

I have set up an example repo that using (most of) client-side functionality of superforms. Maybe it provides enough functionality of superforms to be used in your project, too.

https://stackblitz.com/edit/vitejs-vite-ktneyp?file=src%2FApp.svelte

Nevertheless, it would be nice to have a native adapter inside of superforms to overwrite the interface to sveltekit without that workaround.

FluffyDiscord commented 7 months ago

Interesting solution. It really is hacky tho.

Anton-2 commented 6 months ago

I have set up an example repo that using (most of) client-side functionality of superforms. Maybe it provides enough functionality of superforms to be used in your project, too.

It's working well for me, thanks @philippone.

Note, you can use setError and setMessage successfully without overwriting $app/forms.applyAction() by skipping it with applyAction: false in superForm's options.

Still, having a pure svelte SuperForm.core that can be the base of the current SvelteKit superForm would be really better !

soupman99 commented 5 months ago

@philippone this works great! Thanks so much. Have been fiddling for 2 days.

oscarhermoso commented 5 months ago

https://github.com/benmccann/esm-env is a clean replacement for { browser } (and dev) from '$app/environment';

@sveltejs/kit actually depends on esm-env, so you will have identical functionality

amit13k commented 4 months ago

@philippone Thanks. I made the changes suggested and it allowed me to use superforms with Astro.

gbouteiller commented 2 months ago

Hello everyone, I'd love to see this feature as Superforms is, for me, the best js form library out there but I love both Astro and Sveltekit. In that regard, I have created a small Astro integration to ease the use of Superforms with Astro. PS: by the way, it's my first integration so please be indulgent 😅

reesericci commented 2 weeks ago

I would also love this to make it work properly with actionview-svelte-handler for Rails