Skip to content

Commit

Permalink
[fix] sverdle form reset (#7241)
Browse files Browse the repository at this point in the history
fixes #7238
provides a custom form enhance callback for the demo app /sverdle to prevent form.reset() being called by the default callback.

Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>
  • Loading branch information
eltigerchino and gtm-nayan authored Oct 12, 2022
1 parent ee94584 commit 78becbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-kids-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

fix sverdle guesses incorrectly cleared by form `enhance`
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { confetti } from '@neoconfetti/svelte';
import { enhance } from '$app/forms';
import { applyAction, enhance } from '$app/forms';
import type { PageData, ActionData } from './$types';
import { invalidateAll } from '$app/navigation';
/** @type {import('./$types').PageData} */
export let data: PageData;
Expand Down Expand Up @@ -78,7 +79,19 @@

<svelte:window on:keydown={keydown} />

<form method="POST" action="?/enter" use:enhance>
<form
method="POST"
action="?/enter"
use:enhance={() => {
// prevent default callback from resetting the form
return async ({ result }) => {
if (result.type === 'success') {
await invalidateAll();
}
await applyAction(result);
};
}}
>
<a class="how-to-play" href="/sverdle/how-to-play">How to play</a>

<div class="grid" class:playing={!won} class:bad-guess={form?.badGuess}>
Expand Down

0 comments on commit 78becbb

Please sign in to comment.