forge42dev / remix-hook-form

Open source wrapper for react-hook-form aimed at Remix.run
MIT License
330 stars 27 forks source link

Number validation fails #52

Closed ledniy closed 10 months ago

ledniy commented 10 months ago

Hi there, seems like there's an issue with numbers validation on the backend side, coz if I have z.number() in the schema it will correctly pass validation on the frontend but the action will return an error:

{
  message:  "Expected number, received string"
  type: "invalid_type"
}

I believe that's a bug as in readme you saying it should be parsed as a number image

But based on what I see in the tryParseJSON it will never parse it as a number, also in tests you expecting strings 🤷‍♂️

AlemTuzlak commented 10 months ago

@ledniy Yeah you're right, I've changed it to be passed to the backend as FormData instead of the JSON.stringify() method I was using before, this forces you to coerce types to make sure they are valid, eg z.number({ coerce: true }) for them to work, formData can be sent only as a string/file/blob type hence the reason for this. But in the docs it's outdated. Will change this

AlemTuzlak commented 10 months ago

@ledniy I'll do you one better, there will be no need for you to coerce, I'll handle it inside the package

AlemTuzlak commented 10 months ago

fixed with 3.2