From 059073d4c24e34c142dddd4c150c384779fb51a9 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Sat, 24 May 2025 22:47:24 +0200 Subject: [PATCH] fix: trim whitespaces from string inputs --- frontend/src/lib/utils/form-util.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/utils/form-util.ts b/frontend/src/lib/utils/form-util.ts index 2dcb69f3..8eafee91 100644 --- a/frontend/src/lib/utils/form-util.ts +++ b/frontend/src/lib/utils/form-util.ts @@ -61,7 +61,10 @@ export function createForm>(schema: T, initialValu let values: z.infer | null = null; inputsStore.subscribe((inputs) => { values = Object.fromEntries( - Object.entries(inputs).map(([key, input]) => [key, input.value]) + Object.entries(inputs).map(([key, input]) => { + input.value = trimValue(input.value); + return [key, input.value]; + }) ) as z.infer; })(); @@ -87,6 +90,21 @@ export function createForm>(schema: T, initialValu }); } + // Trims whitespace from string values and arrays of strings + function trimValue(value: any) { + if (typeof value === 'string') { + value = value.trim(); + } else if (Array.isArray(value)) { + value = value.map((item: any) => { + if (typeof item === 'string') { + return item.trim(); + } + return item; + }); + } + return value; + } + return { schema, inputs: inputsStore,