Skip to content

Commit 225b414

Browse files
committed
Added spinner
1 parent c0998f9 commit 225b414

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/routes/tests/delayed-validation/+page.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import { page } from '$app/stores';
66
import SuperDebug from '$lib/client/SuperDebug.svelte';
77
import { debounce } from 'throttle-debounce';
8+
import spinner from './tadpole.svg?raw';
89
910
export let data: PageData;
1011
12+
let checking = false;
13+
1114
async function checkUsername(
1215
username: string,
1316
resolve: (result: string | null) => void
1417
) {
18+
checking = true;
1519
const body = new FormData();
1620
body.set('username', username);
1721
@@ -24,6 +28,7 @@
2428
);
2529
2630
resolve(response.status == 200 ? null : 'This username is taken.');
31+
checking = false;
2732
}
2833
2934
const throttledUsername = debounce(300, checkUsername);
@@ -42,8 +47,6 @@
4247

4348
<h3>Delayed validation</h3>
4449

45-
<SuperDebug data={{ $form, $errors, $tainted }} />
46-
4750
{#if $message}
4851
<h4>Message: {$message}</h4>
4952
{/if}
@@ -65,9 +68,13 @@
6568
data-invalid={$errors.username}
6669
bind:value={$form.username}
6770
/>
68-
{#if 'username' in $errors}<span class="invalid"
69-
>{$errors.username ? '' : ''}</span
70-
>{/if}
71+
{#if checking}
72+
{@html spinner}
73+
{:else if 'username' in $errors}
74+
<span class="invalid">
75+
{$errors.username ? '' : ''}
76+
</span>
77+
{/if}
7178

7279
<div><button>Submit</button></div>
7380
</form>
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)