Skip to content

Commit c8fcbb5

Browse files
author
Sean Wilson
committed
update playground page to handle SchemaForm error event
1 parent a40be41 commit c8fcbb5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/routes/+page.svelte

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Button, { Label as BtnLabel } from "@smui/button"
77
import Textfield from '@smui/textfield';
88
import Snackbar, { Label as SBLabel, Actions } from '@smui/snackbar';
9-
import SchemaForm, { type ValidationError } from "$lib";
9+
import SchemaForm, { ValidationError } from "$lib";
1010
import schemas, { type TestSchema } from "../schemas";
1111
1212
import type UISchema from "$lib/UISchema";
@@ -18,7 +18,7 @@
1818
let schemaString = "";
1919
let uischemaString = "";
2020
let dataString = "";
21-
let validationError: ValidationError | null = null;
21+
let schemaError: Error | ValidationError | null = null;
2222
2323
let schemaForm: SchemaForm;
2424
let errorSnackbar: Snackbar;
@@ -27,7 +27,7 @@
2727
$: setSchemaString(schema);
2828
$: setUISchemaString(uischema);
2929
$: setDataString(data);
30-
$: if (validationError != null) errorSnackbar.open();
30+
$: if (schemaError != null) errorSnackbar.open();
3131
3232
async function setSchemaString(schema: TestSchema["schema"]) {
3333
await tick();
@@ -87,7 +87,7 @@
8787
try {
8888
schemaForm.download();
8989
} catch (error) {
90-
validationError = error as ValidationError;
90+
schemaError = error as Error;
9191
}
9292
}
9393
</script>
@@ -98,21 +98,23 @@
9898
<Label>{tab.name}</Label>
9999
</Tab>
100100
</TabBar>
101-
<SchemaForm {schema} {uischema} bind:data bind:this={schemaForm}>
101+
<SchemaForm {schema} {uischema} bind:data bind:this={schemaForm} on:error={(event) => schemaError = event.detail}>
102102
<Button on:click={download} type="button" variant="raised">
103103
<BtnLabel>Download</BtnLabel>
104104
</Button>
105105
</SchemaForm>
106106

107107
<Snackbar class="schema-error" bind:this={errorSnackbar}>
108108
<SBLabel>
109-
{#if validationError}
110-
{validationError.message}
111-
<ul>
112-
{#each validationError.errors as error}
113-
<li>{error.message}</li>
114-
{/each}
115-
</ul>
109+
{#if schemaError}
110+
{schemaError.message}
111+
{#if schemaError instanceof ValidationError}
112+
<ul>
113+
{#each schemaError.errors as error}
114+
<li>{error.message}</li>
115+
{/each}
116+
</ul>
117+
{/if}
116118
{:else}
117119
Unknown error
118120
{/if}

0 commit comments

Comments
 (0)