Skip to content

Commit c3be12c

Browse files
TommertomTommertom
authored andcommitted
more work on ionic7
1 parent 4a692d2 commit c3be12c

File tree

15 files changed

+273
-615
lines changed

15 files changed

+273
-615
lines changed

demo-app/package-lock.json

Lines changed: 227 additions & 219 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"sveltekit-superforms": "^0.8.1",
3737
"tslib": "^2.4.1",
3838
"typescript": "^4.9.3",
39-
"vite": "^4.0.4",
39+
"vite": "^4.3.4",
4040
"vite-plugin-pwa": "^0.14.1",
4141
"zod": "^3.21.4"
4242
},

demo-app/src/lib/components/Menu.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
.map((componentName) => {
5656
// console.log('COMPONENTN', componentName);
5757
const url =
58-
componentName !== 'Tabs' ? `/components/${componentName}` : `/components/tabs/[tab]`;
58+
componentName !== 'Tabs' ? `/components/${componentName}` : `/components/tabs/explain`;
5959
return {
6060
url,
6161
label: componentName,

demo-app/src/lib/components/SourceViewer.svelte

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// we use a separate way to load the svelte source
6363
// hack the name for tabs
6464
if (name == 'Tabs' || name == 'tabs') {
65-
name = 'tabs/[tab]';
65+
name = 'tabs/explain';
6666
}
6767
6868
console.log('getting', `assets/src/components/${name}/+page.svelte`);
@@ -196,17 +196,15 @@
196196
if (REPLlink.length > 1) {
197197
window.open(REPLlink, '_blank');
198198
}
199-
}}
200-
>
199+
}}>
201200
REPL
202201
</ion-button>
203202
{/if}
204203

205204
<ion-button
206205
on:click={() => {
207206
window.open(APIlink, '_blank');
208-
}}
209-
>
207+
}}>
210208
API
211209
</ion-button>
212210

demo-app/src/routes/components/Inputs/+page.svelte

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,32 @@
22
import SourceButton from '$lib/components/SourceButton.svelte';
33
import { alertController, IonPage } from 'ionic-svelte';
44
5-
import { accountSchema as schema } from './account.interface';
6-
// import { enhance, getFormWritable, validateField } from './spa-enhance';
7-
85
import { superForm, setMessage, setError } from 'sveltekit-superforms/client';
96
import { z } from 'zod';
107
11-
/*
12-
<h1>Edit user</h1>
13-
14-
{#if $message}<h3>{$message}</h3>{/if}
15-
16-
<form method="POST" use:enhance>
17-
<input type="hidden" name="id" bind:value={$form.id} />
18-
19-
<label>
20-
Name<br />
21-
<input
22-
name="name"
23-
data-invalid={$errors.name}
24-
bind:value={$form.name}
25-
{...$constraints.name} />
26-
</label>
27-
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
28-
29-
<label>
30-
E-mail<br />
31-
<input
32-
name="email"
33-
type="email"
34-
data-invalid={$errors.email}
35-
bind:value={$form.email}
36-
{...$constraints.email} />
37-
</label>
38-
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
39-
40-
<button>Submit</button>
41-
</form>
42-
43-
*/
44-
45-
//const form = getFormWritable();
46-
478
const userSchema = z.object({
489
firstName: z.string().min(2).default(''),
4910
lastName: z.string().min(2).default('')
5011
});
5112
13+
type User = z.infer<typeof userSchema>; // not used - but usefull
14+
5215
const { form, errors, message, constraints, enhance, delayed, validate } = superForm(
53-
{ firstName: 'F', lastName: 'ss' },
16+
{ firstName: '', lastName: '' },
5417
{
5518
SPA: true,
5619
validators: userSchema,
5720
onUpdate(form) {
5821
console.log('SUBMIT clicked, received form', form);
5922
},
6023
onError({ result, message }) {
24+
console.log('ERROR received', result, message);
6125
message.set(result.error.message);
6226
},
6327
validationMethod: 'oninput'
6428
}
6529
);
6630
67-
// $: console.log('Form received', $form);
68-
6931
function submit() {
7032
if (!$errors) {
7133
const controller = alertController
@@ -96,29 +58,14 @@
9658
}
9759
}
9860
99-
async function doStuff(e: any) {
100-
console.log('doStuff', e.detail.value, e.target.name);
101-
102-
// const nameErrors = awai validate(e.target.value);
103-
// validate('firstName', { update: 'errors' }).then(console.log);
104-
// validate('lastName', { update: 'errors' }).then(console.log);
61+
async function checkInput(e: any) {
62+
console.log('Getting stuff', e.detail.value, e.target.name);
63+
if (e.target.name in $form) {
64+
//@ts-ignore
65+
$form[e.target.name] = e.detail.value;
66+
}
10567
const nameErrors = await validate('firstName', { update: false });
10668
console.log('validate errors', nameErrors);
107-
/*
108-
109-
const nameErrors = await validate('name', { update: false })
110-
111-
// Validate and update field with a custom value
112-
validate('name', { value: 'Test' })
113-
114-
// Validate a custom value, update errors only
115-
validate('name', { value: 'Test', update: 'errors' })
116-
117-
// Validate and update nested data, and also taint the field
118-
validate(['tags', 1, 'name'], { value: 'Test', taint: true })
119-
120-
121-
*/
12269
}
12370
</script>
12471

@@ -144,30 +91,32 @@ validate(['tags', 1, 'name'], { value: 'Test', taint: true })
14491
<ion-list lines="full" class="ion-no-margin ion-no-padding">
14592
<ion-item>
14693
<ion-input
94+
placeholder="Start typing here to see superforms"
14795
class:ion-invalid={$errors.firstName}
14896
class:ion-touched={$errors.firstName}
149-
label="First Name"
97+
label="First Name - Superforms supercharged"
15098
label-placement="stacked"
15199
helper-text="Here you may enter your first name - or something else"
152100
error-text="Please type more characters..."
153101
name="firstName"
154102
type="text"
155103
value={$form.firstName ?? ''}
156-
on:ionInput={doStuff} />
104+
on:ionInput={checkInput} />
157105
</ion-item>
158106

159107
<ion-item>
160108
<ion-input
109+
placeholder="Start typing here to see superforms"
161110
class:ion-invalid={$errors.lastName}
162111
class:ion-touched={$errors.lastName}
163-
label="Last Name"
112+
label="Last Name - Superforms supercharged"
164113
label-placement="stacked"
165114
helper-text="Here you may enter your last name - or something else"
166115
error-text="Please type more characters..."
167116
name="lastName"
168117
type="text"
169118
value={$form.lastName ?? ''}
170-
on:ionInput={doStuff} />
119+
on:ionInput={checkInput} />
171120
</ion-item>
172121

173122
<ion-item>

demo-app/src/routes/components/Inputs/spa-enhance.ts

Lines changed: 0 additions & 180 deletions
This file was deleted.

demo-app/src/routes/components/Splash/+page.svelte

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,11 @@
3131
<br /> <br />
3232
<br />
3333
<br />
34-
<br /> <br />
35-
<br />
36-
<br />
37-
<br />
3834
<div class="ion-text-center">
3935
<img
4036
src="/assets/svelte-ionic-logo.png"
4137
alt="Great success"
42-
in:scale={{ duration: 1900, easing: elasticInOut }}
43-
/>
38+
in:scale={{ duration: 1900, easing: elasticInOut }} />
4439
<br /><br /><br />
4540
<div in:scale={{ delay: 400, duration: 1900, easing: elasticInOut }}>Great success!</div>
4641
</div>

0 commit comments

Comments
 (0)