diff --git a/src/routes/(app)/devices/[id]/edit/+page.server.ts b/src/routes/(app)/devices/[id]/edit/+page.server.ts index 6590548..984e93e 100644 --- a/src/routes/(app)/devices/[id]/edit/+page.server.ts +++ b/src/routes/(app)/devices/[id]/edit/+page.server.ts @@ -43,6 +43,7 @@ export const load: PageServerLoad = async ({ params }) => { export const actions: Actions = { default: async ({ request, params }) => { const formData = await request.formData(); + const voltages = formData.getAll('voltage') as string[]; const raw = Object.fromEntries(formData); const result = deviceSchema.safeParse(raw); @@ -53,6 +54,7 @@ export const actions: Actions = { const data = result.data; const year = typeof data.year === 'number' ? data.year : null; const locationId = data.locationId || null; + const voltage = voltages.length > 0 ? voltages.join(', ') : null; await db .update(devices) @@ -64,7 +66,7 @@ export const actions: Actions = { serialNumber: data.serialNumber || null, year, condition: data.condition, - voltage: data.voltage || null, + voltage, frequency: data.frequency || null, origin: data.origin || null, faultDescription: data.faultDescription || null, diff --git a/src/routes/(app)/devices/[id]/edit/+page.svelte b/src/routes/(app)/devices/[id]/edit/+page.svelte index 7f93d50..8f10471 100644 --- a/src/routes/(app)/devices/[id]/edit/+page.svelte +++ b/src/routes/(app)/devices/[id]/edit/+page.svelte @@ -10,6 +10,7 @@ let category = $state(form?.values?.category ?? d.category); let brand = $state(String(form?.values?.brand ?? d.brand ?? '')); let model = $state(String(form?.values?.model ?? d.model ?? '')); + const existingVoltages = (d.voltage ?? '').split(',').map((v: string) => v.trim()).filter(Boolean); @@ -87,13 +88,13 @@
- {#each VOLTAGE_OPTIONS as v} - + {/each} +

Ctrl+click for multiple

diff --git a/src/routes/(app)/devices/new/+page.server.ts b/src/routes/(app)/devices/new/+page.server.ts index b63f56a..733ff30 100644 --- a/src/routes/(app)/devices/new/+page.server.ts +++ b/src/routes/(app)/devices/new/+page.server.ts @@ -34,6 +34,7 @@ export const load: PageServerLoad = async () => { export const actions: Actions = { default: async ({ request }) => { const formData = await request.formData(); + const voltages = formData.getAll('voltage') as string[]; const raw = Object.fromEntries(formData); const result = deviceSchema.safeParse(raw); @@ -44,6 +45,7 @@ export const actions: Actions = { const data = result.data; const year = typeof data.year === 'number' ? data.year : null; const locationId = data.locationId || null; + const voltage = voltages.length > 0 ? voltages.join(', ') : null; const [device] = await db .insert(devices) @@ -55,7 +57,7 @@ export const actions: Actions = { serialNumber: data.serialNumber || null, year, condition: data.condition, - voltage: data.voltage || null, + voltage, frequency: data.frequency || null, origin: data.origin || null, initialCondition: data.initialCondition || null, diff --git a/src/routes/(app)/devices/new/+page.svelte b/src/routes/(app)/devices/new/+page.svelte index 5cf19fb..55979bd 100644 --- a/src/routes/(app)/devices/new/+page.svelte +++ b/src/routes/(app)/devices/new/+page.svelte @@ -87,13 +87,13 @@
- {#each VOLTAGE_OPTIONS as v} - + {/each} +

Ctrl+click for multiple