S
SolidJS5mo ago
sh1man

how do you usually convert a form field from string to number on rpc servershould i use valibot to

helps pls
1 Reply
sh1man
sh1man5mo ago
Schema
export const EmrErrorSchema = object({
id: optional(string()),
hostname: string([minLength(1)]),
emr: number(),
errorMessage: string([minLength(1)]),
nameErrorMessage: string([minLength(1)]),
errorCategoryId: string(),
});
export const EmrErrorSchema = object({
id: optional(string()),
hostname: string([minLength(1)]),
emr: number(),
errorMessage: string([minLength(1)]),
nameErrorMessage: string([minLength(1)]),
errorCategoryId: string(),
});
Input
<TextFieldInput
name="emr"
color="neutral"
placeholder="1"
type="number"
variant="bordered"
/>
<TextFieldInput
name="emr"
color="neutral"
placeholder="1"
type="number"
variant="bordered"
/>
RPC
export async function updateOrCreateEmrErrorServerAction(form: FormData) {
const decoded = decode(form);
const parsed = await safeParseAsync(EmrErrorSchema, decoded);
if (!parsed.success) {
return rpcParseIssueResult(parsed.issues);
}
const { id, hostname, emr, errorMessage, nameErrorMessage, errorCategoryId } = parsed.output;

if (id) {
await db_client.emrError.update({
where: { id },
data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId }
});
return reload({revalidate:EMR_ERRORS_CACHE_KEY});
} else {
await db_client.emrError.create({
data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId }
});
return reload({revalidate:EMR_ERRORS_CACHE_KEY});
}
}
export async function updateOrCreateEmrErrorServerAction(form: FormData) {
const decoded = decode(form);
const parsed = await safeParseAsync(EmrErrorSchema, decoded);
if (!parsed.success) {
return rpcParseIssueResult(parsed.issues);
}
const { id, hostname, emr, errorMessage, nameErrorMessage, errorCategoryId } = parsed.output;

if (id) {
await db_client.emrError.update({
where: { id },
data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId }
});
return reload({revalidate:EMR_ERRORS_CACHE_KEY});
} else {
await db_client.emrError.create({
data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId }
});
return reload({revalidate:EMR_ERRORS_CACHE_KEY});
}
}
Error emr param Invalid type: Expected number but received "444"