#I'm using mantine `useForm` with `zod` and have an issue with optional int.

4 messages ยท Page 1 of 1 (latest)

cedar sky
#

Hello!
I'm using mantine useForm with zod and have an issue with optional int.
Initial value is null, validation works well, until I add int value and delete it, after that I'm getting "Expected number, received string".
Is it a bug?
"@mantine/*": "^7.5.3",

verbal fulcrum
cedar sky
#

I see, thank you!

whole garnet
#

Depending on your situation you can try use

const mantineNumber = z.coerce.number().nullable();

or this may work better, keeping null when number input is empty after having value typed in

const mantineNumber = z.number().or(z.literal(โ€œโ€)).nullable().transform(val=>val===โ€œโ€?null:val)