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

Recipe or provided function to ease working with multiple form submissions #7175

Open
dummdidumm opened this issue Oct 7, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation feature / enhancement New feature or request forms Stuff relating to forms and form actions p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Milestone

Comments

@dummdidumm
Copy link
Member

dummdidumm commented Oct 7, 2022

Describe the problem

export let form and $page.form are designed around having one form submitted at a time - which is the only way possible when JavaScript is disabled. When JavaScript is enabled however, you could have multiple in-flight form submissions at the same time. This is doable today in user-land, but maybe not immediately obvious how to do. #7120 is a symptom of that.

Describe the proposed solution

Either add a recipe that shows how to implement something like that, and/or provide a helper function that eases this.

One possibility would be to provide some kind of form creator function which you create for each form:

<script>
  const { form, state, action, enhance } = createForm('/?named-action');
</script>

<form method="POST" action={action} use:enhance>
  <input name="username" />
  {#if $form.usernameInvalid}
    <span>Username invalid</span>
  {/if}
  <button disabled={$state.submitting}>Submit</button
</form>

Calling createForm creates a encapsulated instance of a form life cycle with stores to track the submission state etc. Multiple of these can be used at once, for example inside a list of TODOs.

Another nice-to-have would be to have each instance from createForm be part of some app-wide context so you can see which submissions are currently running etc and show optimistic UI/loading spinners depending on that. Depending on how tight we want to couple this to built-ins, this would either be a custom-made setContext call at the desired place, or a global $page.forms

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@dummdidumm dummdidumm added documentation Improvements or additions to documentation feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. forms Stuff relating to forms and form actions labels Oct 7, 2022
@dummdidumm dummdidumm added this to the whenever milestone Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature / enhancement New feature or request forms Stuff relating to forms and form actions p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

No branches or pull requests

1 participant