-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Opt-out of data-svelte-h
#10992
Comments
This isn't related to |
I thought it was a <!-- src/routes/temp/+page.svelte -->
<script lang="ts">
import { enhance } from '$app/forms';
export let form;
$: console.log(form);
</script>
<form
method="post"
use:enhance
on:submit={(e) => {
if (e.submitter instanceof HTMLButtonElement) e.submitter.disabled = true;
}}
>
{#if !form || form.date}
{#if !form}
<!-- Static element with `data-svelte-h` attribute. -->
<button>Submit</button>
{:else}
<button>Submit</button>
{/if}
{/if}
</form> // +page.server.ts
export const actions = {
default: () => ({ date: new Date() }),
}; And yes, I newly learned that the
Even with this knowledge, I am having a hard time understanding the o.g. reproduction.
Why doesn't the following each block re-run, despite an updated {#each formArray as _}
<button use:action formaction="?/date">Fail1</button>
{/each} The only case I'm using this is to block double submission under JavaScript. |
It's not doing it the first time because the |
If this is not a bug but an intended behavior, this issue can be closed. I am not sure what to rename the title to. It seems misleading. The intention of this issue was to workaround the following workaround. <script lang="ts">
import { enhance } from '$app/forms';
export let form;
// Restrict form double submit by disabling the element that sent the submit event.
// Reference https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent/submitter
const disableSubmitter = (e: SubmitEvent) => {
if (e.submitter instanceof HTMLButtonElement || e.submitter instanceof HTMLInputElement) {
e.submitter.disabled = true;
}
};
</script>
<form method="post" use:enhance on:submit={disableSubmitter}>
<!-- Remove the disabled submit button and recreate one afterwards. -->
{#if !form}
<button>Submit</button>
{:else}
<button>Submit</button>
{/if}
</form> |
Describe the bug
In the following example, even if the form's default action returns
{ date: new Date() }
formArray
is updated and therefore logged in the console.<button>
element is not recreated, since it has adata-svelte-h
attribute.<button>
element stays disabled.Reproduction
Reference the StackBlitz project.
The reproduction's goal is to disable the submit button until the form action responds, thus blocking double submit.
Logs
System Info
Severity
annoyance
Additional Information
data-svelte-h
attributes.{#if form}
seems to be enough to recreate Fail3 button.The text was updated successfully, but these errors were encountered: