1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-04 12:46:45 +00:00

fix: trim whitespaces from string inputs

This commit is contained in:
Elias Schneider
2025-05-24 22:47:24 +02:00
parent e19b33fc2e
commit 059073d4c2

View File

@@ -61,7 +61,10 @@ export function createForm<T extends z.ZodType<any, any>>(schema: T, initialValu
let values: z.infer<T> | 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<T>;
})();
@@ -87,6 +90,21 @@ export function createForm<T extends z.ZodType<any, any>>(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,