File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
src/routes/tests/delayed-validation Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 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
2428 );
2529
2630 resolve (response .status == 200 ? null : ' This username is taken.' );
31+ checking = false ;
2732 }
2833
2934 const throttledUsername = debounce (300 , checkUsername );
4247
4348<h3 >Delayed validation</h3 >
4449
45- <SuperDebug data ={{ $form , $errors , $tainted }} />
46-
4750{#if $message }
4851 <h4 >Message: {$message }</h4 >
4952{/if }
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 >
You can’t perform that action at this time.
0 commit comments