techniq / svelte-ux

Collection of Svelte components, actions, stores, and utilities to build highly interactive applications.
https://svelte-ux.techniq.dev/
MIT License
830 stars 46 forks source link

Submitting a form #492

Closed kasleet closed 1 month ago

kasleet commented 1 month ago

I build a form with zod schema validation just as in the examples. However, I want to actually try to submit the form. I'm not that versed with Svelte, but I have seen that Form.svelte is preventing submit from actually submitting the form and only to update the state?

I guess that is intended, but is there a way to "just" submit the form?

techniq commented 1 month ago

Hey @kasleet 👋, thanks for checking out Svelte UX!

Form is a lightweight wrapper around formStore and a <form> element and traditionally have used it for client-side only form handling, as you can also use formStore directly with your own <form> instance when needed.

With that said, supporting submitting the form to the server should still be possible, so I just PR'd a fix that only prevents if the form is not valid or no action/method are set (still supporting the client-side only use case). This means setting <Form method="post"> (default Sveltekit action) or <Form action="?/login"> (named action, or other endpoint) will now submit the form to the server if valid.

This is now available in 0.75.0. Let me know how that works out.