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

Add submitting state to page store #7120

Closed
KoichiKiyokawa opened this issue Oct 2, 2022 · 3 comments
Closed

Add submitting state to page store #7120

KoichiKiyokawa opened this issue Oct 2, 2022 · 3 comments

Comments

@KoichiKiyokawa
Copy link
Contributor

KoichiKiyokawa commented Oct 2, 2022

Describe the problem

First, thank you for all of your work in SvelteKit.
It's common to disable the submit button during form submission to prevent users from submitting multiple times.
But now, we need some boilerplate code to do it. cf) #7041
It would be nice if SvelteKit provides the submitting state by page store.

Describe the proposed solution

  • $page.formSubmitting ?
  • $page.form.submitting ?
  • and so on
<script>
import { page } from '$app/store'
</script>

<button disable={$page.formSubmitting}>submit</button>

Alternatives considered

No response

Importance

nice to have

Additional Information

FYI: Remix can handle it by the followings,

function SubmitButton() {
  const transition = useTransition();

  return <button type="submit" disable={transition.state === "submitting"}>submit</button>;
}

https://remix.run/docs/en/v1/api/remix#transitionstate

@mustofa-id
Copy link

but what if there is multiple forms in a page?

@KoichiKiyokawa
Copy link
Contributor Author

KoichiKiyokawa commented Oct 5, 2022

but what if there is multiple forms in a page?

Good point of view. I had missed it. Thank you!
How about $page.forms[0].submitting for the first form? (Like Document.forms)

Current SvelteKit already has $page.form (https://kit.svelte.dev/docs/types#sveltejs-kit-page), but maybe it is only for a single form. Does it also has to consider multiple forms in a page?

@dummdidumm
Copy link
Member

export let form and $page.form are designed to work with the latest submitted form. It is not designed to work with multiple in-flight forms at the same time. Adding your own submission state using the use:enhance action is done quick:

<script>
  import { enhance } from '$app/forms';

  let submitting = false;
</script>

<form method="POST" use:enhance={() => {
  submitting = true;
  return ({ update }) => {
    submitting = false;
    update();
  }
}}>
  ...
</form>

I think the bigger desire here is to have more info and/or a provided function to make these more advanced uses cases (multiple in-flight submissions, submission state) easy to implement. I opened #7175 for this, closing in favor of that.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants