Closed beerose closed 3 years ago
Hey @beerose! You do that in react-final-form with the parse
option which you can add to the useField
options.
parse: (value) => Number(value)
Hey @flybayer! Thanks for the answer. I get it, but the thing is that the starter code doesn't work out of the box with types other than string.
I was hoping that it could be covered in the generated code — either inside a function that is passed as validate
prop to FinalForm
component or inside starter components using useField
hook.
The point isn't how to do this, but rather that it would be cool to have other types working out of the box as well.
It's more of a question of expectations. In my opinion, the starter code should either do less (have fewer abstractions on forms and, for example, use FinalForm inline), or do more (work with different form values types).
Hi folks :wave:
Seeing "number"
in LabeledTextField
types I expect I can use it with numbers, and I'd expect it just works with zod
and the Form
component from components/Form.tsx.
Removing this "number"
would also solve the problem for me and tell me "write your own number input, mate", this one doesn't support numbers.
This change (based on https://github.com/blitz-js/legacy-framework/issues/988) would also satisfy that number
in types IMHO.
Thanks for the suggestion @hasparus, it solves the issue nicely on my end.
@hasparus @Kosai106 yes, that's a very good change! One of you want to make a PR for that?
I'm facing the same issue with react-hook-form. Can someone please suggest a fix for the same?
@vivek7405 probably this will do it: https://react-hook-form.com/advanced-usage#TransformandParse
Thanks @beerose, will give it a try
What is the problem?
Form values are not parsed before validation in Blitz setup with React Final Form.
Steps to Reproduce
age (number)
to, for example, sign up form (or any other form).age
with some value.Expected number, received string
error:Versions
I guess the generated
Form.tsx
has a missing step — a transformation of the values before the validation:I could submit a PR with a fix if no one else is working on it.
cc @zolwiastyl @hasparus