Help on a Shadcn Form default value
I have a shadcn Form Number input with a default value of 40 (this value comes from database).
Because i was having an issue with”Expected a number, received string” error on my number input i added a parseInt to the field onChange.
But now when I delete the value so that the input is empty it defaults back to 40 instead of being empty. This is bad ux and i’ve been trying to fix this for hours but no LLM has been able to help me… seems a simple fix.
Thank you so much in advance.
5 Replies
Are you checking for empty strings before parsing?
yes, “field.onChange(value === "" ? "" : parseInt(value, 10));”
but it still gets changed to the defaultValues
Have you tried it using logical OR? or valueAsNumber?
yes i’ve tried all of those 😦
I honestly think react-hook-form is changing the undefined to the defaultValue.
That's really weird behavior. Can you share some code?