ciscoheat / sveltekit-superforms

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

Custom callback for when submission is completed #371

Open saturnonearth opened 8 months ago

saturnonearth commented 8 months ago

Is your feature request related to a problem? Please describe. For example...if I am redirecting on login I want the loading spinner to stay on even though the form is done submitting.

Describe the solution you'd like I think it would be cool to have $redirecting store, like $delayed and $submitting so we can easily track it.

Describe alternatives you've considered I could just easily add a flag onResult but I think it would be nice to have the Store easily accessible, like the others are.

ciscoheat commented 8 months ago

This is already included in the timers, if a redirect result is returned, then the SvelteKit navigation store is used to clear the timers. If that doesn't work for you, something isn't right. Can you make a MRE?

saturnonearth commented 8 months ago

This is already included in the timers, if a redirect result is returned, then the SvelteKit navigation store is used to clear the timers. If that doesn't work for you, something isn't right. Can you make a MRE?

Here is a MRE: https://stackblitz.com/edit/superforms-2-testing-qcncdj?file=src%2Froutes%2F%2Bpage.svelte

I wonder if it's because of the page transition?

ciscoheat commented 8 months ago

When I submit on the MRE, the spinner is visible up until the transition, isn't that how it's supposed to be?

saturnonearth commented 8 months ago

When I submit on the MRE, the spinner is visible up until the transition, isn't that how it's supposed to be?

Well technically speaking I suppose yes, but it's a little jarring during a transition when the button state changes. I could just add a flag but was thinking of a cleaner way to do this as it's a common pattern for me, and I often already have $delayed or $submitting on the submit button - but perhaps it's unnecessary

ciscoheat commented 8 months ago

Then I guess SvelteKit doesn't take transitions into account for the navigation store. Some future version of Superforms may have a custom callback for when the submission is determined to be completed, but not right now. :)