Event form
A gathering form with native date, time, color, number, slider, radio, checklist, checkbox and multiline inputs.
What it demonstrates: Typed native fields · explicit saving · responsive rows · action validation.
Run this example
All learning examples are available in your developer world on scape.wtf. To edit this example, clone the public Scape tools repository and run its project with Node.js 22+:
sh
git clone https://github.com/scape-wtf/scape-tools.git
cd scape-tools
npm install
cd examples/gizmos/event-form
npm run build
npm test
npm exec -- scape gizmo dev1
2
3
4
5
6
7
2
3
4
5
6
7
This connects to https://scape.wtf. Follow connection and approval. To make an independent project, copy this example directory outside the checkout, then run npm install, npm run build, npm test and npm exec -- scape gizmo dev there. Its manifest uses published SDK and CLI dependencies. The project's npm run dev script is a shortcut for scape gizmo dev.
Try changing it
Change capacity and visitor access, adjust duration, choose a format and activities, pick a custom color, and add multiline notes. Leave a required date or time empty to check rejection. Date, time and timezone stay separate; the example does not schedule notifications. See the form walkthrough for validation and calendar semantics.
Source
This code is included directly from the working example when the site builds.
src/definition.ts
ts
/** Calendar values remain separate; this example never converts them to a timestamp. */
import {
defineObject,
exactKeys,
ObjectActionError,
record,
validObjectFieldValue,
type ObjectField,
type ObjectViewRow,
} from '@scape-wtf/sdk';
export interface EventState {
// Optional additions keep earlier placements readable without rewriting saved state.
name?: string;
duration?: number;
format?: string;
activities?: string[];
date: string;
time: string;
timezone: string;
color: string;
capacity: number;
open: boolean;
notes: string;
}
const addedDefaults = { name: '', duration: 60, format: 'social', activities: [] as string[] };
export const eventFields = (state: EventState): ObjectField[] => [
{
id: 'name',
label: 'Event name',
kind: 'text',
value: state.name ?? addedDefaults.name,
maxLength: 80,
},
{
id: 'date',
label: 'Date',
kind: 'date',
value: state.date,
min: '2026-01-01',
max: '2099-12-31',
},
{ id: 'time', label: 'Time', kind: 'time', value: state.time, min: '00:00', max: '23:59' },
{
id: 'timezone',
label: 'Timezone',
kind: 'select',
value: state.timezone,
options: [
{ value: 'UTC', label: 'UTC' },
{ value: 'America/Edmonton', label: 'America/Edmonton' },
],
},
{
id: 'color',
label: 'Color',
kind: 'color',
value: state.color,
palette: ['#ff8800', '#0099ff', '#44bb66'],
},
{
id: 'capacity',
label: 'Capacity',
kind: 'number',
value: state.capacity,
min: 1,
max: 100,
step: 1,
},
{
id: 'duration',
label: 'Duration (minutes)',
kind: 'slider',
value: state.duration ?? addedDefaults.duration,
min: 15,
max: 180,
step: 15,
},
{
id: 'format',
label: 'Format',
kind: 'radio',
value: state.format ?? addedDefaults.format,
options: [
{ value: 'social', label: 'Social' },
{ value: 'workshop', label: 'Workshop' },
],
},
{
id: 'activities',
label: 'Activities',
kind: 'checklist',
value: state.activities ?? [],
options: [
{ value: 'music', label: 'Music' },
{ value: 'games', label: 'Games' },
{ value: 'tour', label: 'World tour' },
],
},
{ id: 'open', label: 'Open to visitors', kind: 'boolean', value: state.open },
{
id: 'notes',
label: 'Notes',
kind: 'text',
value: state.notes,
maxLength: 1000,
multiline: true,
},
];
const initial = (): EventState => ({
...addedDefaults,
activities: [],
date: '',
time: '',
timezone: 'UTC',
color: '#0099ff',
capacity: 10,
open: true,
notes: '',
});
const valid = (state: unknown): state is EventState => {
if (
!record(state) ||
!exactKeys(state, [
'name',
'date',
'time',
'timezone',
'color',
'capacity',
'open',
'notes',
'duration',
'format',
'activities',
])
)
return false;
const values: Record<string, unknown> = { ...addedDefaults, ...state };
return eventFields(initial()).every(field => validObjectFieldValue(field, values[field.id]));
};
export const eventForm = defineObject<EventState>({
type: 'scape.event-form',
version: 1,
emoji: '📝',
label: 'Event form',
hint: 'Plan a gathering',
initial,
valid,
actions: {
save: {
permission: 'editor',
run: (_state, payload) => {
if (!valid(payload) || !payload.date || !payload.time)
throw new ObjectActionError(400, 'Choose a date and time and check the event details');
return { ...addedDefaults, ...payload, activities: [...(payload.activities ?? [])] };
},
},
},
view: (state, viewer) => ({
title: state.name || 'Event form',
description: state.date
? `${state.date} · ${state.time} (${state.timezone})`
: 'Choose a calendar date, local time and explicit timezone.',
items: state.notes
? [
{
id: 'notes',
title: state.open ? 'Visitors welcome' : 'Private gathering',
description: state.notes,
},
]
: [],
rows: [
...(state.notes
? [
{
id: 'summary',
label: 'Event details',
elements: [{ kind: 'description' }, { kind: 'item', id: 'notes' }],
} satisfies ObjectViewRow,
]
: []),
...(viewer.canEdit
? ([
{ id: 'name', elements: [{ kind: 'field', id: 'name' }] },
{
id: 'when',
label: 'Date and time',
elements: [
{ kind: 'field', id: 'date' },
{ kind: 'field', id: 'time' },
],
},
{ id: 'timezone', elements: [{ kind: 'field', id: 'timezone' }] },
{ id: 'color', elements: [{ kind: 'field', id: 'color' }] },
{
id: 'attendance',
label: 'Attendance',
elements: [
{ kind: 'field', id: 'capacity' },
{ kind: 'field', id: 'open' },
],
},
...['duration', 'format', 'activities'].map(id => ({
id,
elements: [{ kind: 'field' as const, id }],
})),
{
id: 'save',
sizing: 'content',
elements: [
{ kind: 'field', id: 'notes' },
{ kind: 'control', id: 'save' },
],
},
] satisfies ObjectViewRow[])
: []),
],
fields: viewer.canEdit ? eventFields(state) : [],
controls: viewer.canEdit
? [
{
id: 'save',
label: 'Save event',
fields: eventFields(state).map(field => field.id),
action: { name: 'save', payload: {} },
},
]
: [],
}),
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
src/project.ts
ts
import { defineProject } from '@scape-wtf/sdk';
import { eventForm } from './definition.js';
export default defineProject({
name: 'Event form',
description:
'Every native form field: text, select, date, time, colors, number, checkbox and notes.',
objects: [eventForm],
});1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
