mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-04 15:39:45 +00:00
fix: trim whitespaces from string inputs
This commit is contained in:
@@ -61,7 +61,10 @@ export function createForm<T extends z.ZodType<any, any>>(schema: T, initialValu
|
|||||||
let values: z.infer<T> | null = null;
|
let values: z.infer<T> | null = null;
|
||||||
inputsStore.subscribe((inputs) => {
|
inputsStore.subscribe((inputs) => {
|
||||||
values = Object.fromEntries(
|
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>;
|
) 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 {
|
return {
|
||||||
schema,
|
schema,
|
||||||
inputs: inputsStore,
|
inputs: inputsStore,
|
||||||
|
|||||||
Reference in New Issue
Block a user